Forráskód Böngészése

Merge branch 'master' of http://116.63.46.168:3000/ADPilot/modularization

pilot 1 éve
szülő
commit
a6b17b956f
26 módosított fájl, 46 hozzáadás és 858 törlés
  1. 0 0
      src/detection/trafficlight_detection/calibrate_camera.py
  2. 0 0
      src/detection/trafficlight_detection/calibrate_camera_new.py
  3. 0 0
      src/detection/trafficlight_detection/include/Hungarian.h
  4. 0 0
      src/detection/trafficlight_detection/include/KalmanTracker.h
  5. 0 0
      src/detection/trafficlight_detection/include/detect_obstacle.h
  6. 0 0
      src/detection/trafficlight_detection/include/imageBuffer.h
  7. 44 29
      src/detection/trafficlight_detection/main.cpp
  8. 0 0
      src/detection/trafficlight_detection/saveVideo.py
  9. 0 0
      src/detection/trafficlight_detection/src/Hungarian.cpp
  10. 0 0
      src/detection/trafficlight_detection/src/KalmanTracker.cpp
  11. 0 0
      src/detection/trafficlight_detection/src/detect_obstacle.cpp
  12. 2 2
      src/detection/trafficlight_detection/trafficlight.pro
  13. 0 0
      src/detection/trafficlight_detection/yaml/camera.yaml
  14. 0 0
      src/detection/trafficlight_detection/yaml/camera147.yaml
  15. 0 0
      src/detection/trafficlight_detection/yaml/camera_middle_640_360.yaml
  16. 0 0
      src/detection/trafficlight_detection/yaml/init.yaml
  17. 0 0
      src/detection/trafficlight_detection/yaml/pers_ori.yaml
  18. 0 701
      src/detection/yolov5-trt-v2.0/main.cpp
  19. 0 12
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/camera.yaml
  20. 0 12
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/camera_ori.yaml
  21. 0 16
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/init.yaml
  22. 0 19
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers.yaml
  23. 0 19
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers3.yaml
  24. 0 19
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers_1.yaml
  25. 0 19
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers_2.yaml
  26. 0 10
      src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers_ori.yaml

+ 0 - 0
src/detection/yolov5-trt-v2.0/calibrate_camera.py → src/detection/trafficlight_detection/calibrate_camera.py


+ 0 - 0
src/detection/yolov5-trt-v2.0/calibrate_camera_new.py → src/detection/trafficlight_detection/calibrate_camera_new.py


+ 0 - 0
src/detection/yolov5-trt-v2.0/include/Hungarian.h → src/detection/trafficlight_detection/include/Hungarian.h


+ 0 - 0
src/detection/yolov5-trt-v2.0/include/KalmanTracker.h → src/detection/trafficlight_detection/include/KalmanTracker.h


+ 0 - 0
src/detection/yolov5-trt-v2.0/include/detect_obstacle.h → src/detection/trafficlight_detection/include/detect_obstacle.h


+ 0 - 0
src/detection/yolov5-trt-v2.0/include/imageBuffer.h → src/detection/trafficlight_detection/include/imageBuffer.h


+ 44 - 29
src/detection/yolov5-trt-v2.0/main_new.cpp → src/detection/trafficlight_detection/main.cpp

@@ -55,15 +55,41 @@ struct Bbox {
 };
 
 
+const char* onnx_path = "./model/yolov5s_640_old+new.onnx"; //onnx path
+const std::string engine_path = "./model/yolov5s_640_old+new.engine"; // engine paths
+
+bool imshow_flag = true;
+
 float conf_thr = 0.5;
 float nms_thr = 0.4;
 
 const bool calibrationstate = false;
-const bool cropstate = false;
+const std::string calibration_yamlpath = "./yaml/camera_middle_640_360.yaml";
+
+
+const bool cropstate = true;
 cv::Range crop_height = cv::Range(40,680);
 cv::Range crop_width = cv::Range(320,960);
+
+
+bool test_video = false;
+//string video_path = "v4l2src device=/dev/video0 ! video/x-raw, width=(int)1280, height=(int)720 ! videoconvert ! appsink";
+string video_path = "/home/nvidia/code/modularization/src/detection/trafficlight_detection/data/camera_test3.mp4";
+
+//是否开启跟踪
 const bool trackstate = true;
 
+void * gpbrain;  //获取红绿灯开启状态
+string brainname = "brainstate";
+bool lightstart = true;
+
+void * gpcamera;
+string cameraname="image00";
+ConsumerProducerQueue<cv::Mat> * imageBuffer =  new ConsumerProducerQueue<cv::Mat>(3,true);
+
+void * gpdetect;
+string detectname = "lightarray";  //检测结果
+
 // stuff we know about the network and the input/output blobs
 static const int INPUT_H = 640;
 static const int INPUT_W = 640;
@@ -75,29 +101,11 @@ static const int OUTPUT_SIZE = 1* anchor_output_num *(cls_num+5); //1000 * sizeo
 const char* INPUT_BLOB_NAME = "images";
 const char* OUTPUT_BLOB_NAME = "output";
 
-const char* onnx_path = "/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/model/yolov5s_640_old+new.onnx"; //onnx path
-const std::string engine_path = "/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/model/yolov5s_640_old+new.engine"; // engine path
 IExecutionContext* context;
 ICudaEngine* engine;
 IRuntime* runtime;
 float* prob;
 
-bool test_video = true;
-//string video_path = "v4l2src device=/dev/video0 ! video/x-raw, width=(int)1280, height=(int)720 ! videoconvert ! appsink";
-string video_path = "/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/data/camera_test4.mp4";
-
-void * gpcamera;
-string cameraname="image00";
-ConsumerProducerQueue<cv::Mat> * imageBuffer =  new ConsumerProducerQueue<cv::Mat>(3,true);
-
-void * gpbrain;  //获取红绿灯开启状态
-string brainname = "brainstate";
-bool lightstart = true;
-
-void * gpdetect;
-string detectname = "lightarray";  //检测结果
-
-
 iv::Ivfault *gfault = nullptr;
 iv::Ivlog *givlog = nullptr;
 
@@ -716,7 +724,7 @@ int main(int argc, char** argv)
 //================================== camera calib init ==========================
     if (calibrationstate)
     {
-        cv::FileStorage calib_file("/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/yaml/camera_middle_640_360.yaml", cv::FileStorage::READ);
+        cv::FileStorage calib_file(calibration_yamlpath, cv::FileStorage::READ);
         calib_file["cameraMatrix"]>>camera_matrix;
         calib_file["distCoeffs"]>>dist_coe;
         cv::Mat R = cv::Mat::eye(3, 3, CV_64F);
@@ -837,21 +845,28 @@ int main(int argc, char** argv)
                 cv::resize(frame, frame, cv::Size(INPUT_W, INPUT_H), 0, 0, cv::INTER_LINEAR);
                 res_img=draw_rect(frame,results_final);
 
+                std::cout<<"light number: "<<results_final.size()<<std::endl;
+
                 results.clear();
                 results_track.clear();
                 results_final.clear();
 
-                cv::namedWindow("Result",cv::WINDOW_NORMAL);
-                cv::imshow("Result",frame);
-                if(cv::waitKey(10) == 'q')
+                if (imshow_flag)
                 {
-                    cv::destroyAllWindows();
-                    //yolo_context->destroy();
-                    //start_up = false;
-                    break;
+
+                    cv::namedWindow("Result",cv::WINDOW_NORMAL);
+                    cv::imshow("Result",frame);
+                    if(cv::waitKey(10) == 'q')
+                    {
+                        cv::destroyAllWindows();
+                        //yolo_context->destroy();
+                        //start_up = false;
+                        break;
+                    }
+                    if(cv::waitKey(1) == 's')
+                        cv::waitKey(0);
                 }
-                if(cv::waitKey(1) == 's')
-                    cv::waitKey(0);
+
                 //writer << frame;
                 //waittime = (double)cv::getTickCount();
                 if(!lightstart)

+ 0 - 0
src/detection/yolov5-trt-v2.0/saveVideo.py → src/detection/trafficlight_detection/saveVideo.py


+ 0 - 0
src/detection/yolov5-trt-v2.0/src/Hungarian.cpp → src/detection/trafficlight_detection/src/Hungarian.cpp


+ 0 - 0
src/detection/yolov5-trt-v2.0/src/KalmanTracker.cpp → src/detection/trafficlight_detection/src/KalmanTracker.cpp


+ 0 - 0
src/detection/yolov5-trt-v2.0/src/detect_obstacle.cpp → src/detection/trafficlight_detection/src/detect_obstacle.cpp


+ 2 - 2
src/detection/yolov5-trt-v2.0/yolov5-trt-v2.0.pro → src/detection/trafficlight_detection/trafficlight.pro

@@ -20,10 +20,10 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
 !isEmpty(target.path): INSTALLS += target
 
 
-INCLUDEPATH += yolov5-trt-v2.0/include \
+INCLUDEPATH += trafficlight_detection/include \
                include
 
-SOURCES += main_new.cpp \
+SOURCES += main.cpp \
            src/Hungarian.cpp \
            src/KalmanTracker.cpp \
            src/detect_obstacle.cpp\

+ 0 - 0
src/detection/yolov5-trt-v2.0/yaml/camera.yaml → src/detection/trafficlight_detection/yaml/camera.yaml


+ 0 - 0
src/detection/yolov5-trt-v2.0/yaml/camera147.yaml → src/detection/trafficlight_detection/yaml/camera147.yaml


+ 0 - 0
src/detection/yolov5-trt-v2.0/yaml/camera_middle_640_360.yaml → src/detection/trafficlight_detection/yaml/camera_middle_640_360.yaml


+ 0 - 0
src/detection/yolov5-trt-v2.0/yaml/init.yaml → src/detection/trafficlight_detection/yaml/init.yaml


+ 0 - 0
src/detection/yolov5-trt-v2.0/yaml/pers_ori.yaml → src/detection/trafficlight_detection/yaml/pers_ori.yaml


+ 0 - 701
src/detection/yolov5-trt-v2.0/main.cpp

@@ -1,701 +0,0 @@
-#include "NvInfer.h"
-#include "cuda_runtime_api.h"
-#include <fstream>
-#include <iostream>
-#include <map>
-#include <sstream>
-#include <vector>
-#include <chrono>
-#include <cmath>
-#include <cassert>
-
-
-#include<opencv2/core/core.hpp>
-#include<opencv2/highgui/highgui.hpp>
-#include <opencv2/opencv.hpp>
-
-#include "modulecomm.h"
-#include "xmlparam.h"
-#include "ivfault.h"
-#include "ivlog.h"
-#include "ivexit.h"
-#include "ivversion.h"
-#include "rawpic.pb.cc"
-#include "lightarray.pb.h"
-#include "brainstate.pb.h"
-#include <QCoreApplication>
-#include <thread>
-#include "opencv2/imgcodecs/legacy/constants_c.h"
-#include "qmutex.h"
-#include "condition_variable"
-
-// onnx转换头文件
-#include "NvOnnxParser.h"
-using namespace nvonnxparser;
-
-const std::string engine_path = "/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/best-640.engine"; // engine path
-
-cv::Mat camera_matrix,dist_coe,map1,map2;
-float time_read_img = 0.0;
-float time_infer = 0.0;
-cv::Mat res_img; // result image
-int time_num = 0;
-
-float* prob;
-using namespace nvinfer1;
-
-IExecutionContext* context;
-ICudaEngine* engine;
-IRuntime* runtime;
-
-
-bool gbstate = true;
-void * gp;
-void * gpdetect;
-iv::Ivfault *gfault = nullptr;
-iv::Ivlog *givlog = nullptr;
-
-
-using namespace std;
-
-
-#define CHECK(status) \
-    do\
-    {\
-        auto ret = (status);\
-        if (ret != 0)\
-        {\
-            std::cerr << "Cuda failure: " << ret << std::endl;\
-            abort();\
-        }\
-    } while (0)
-struct  Detection {
-    //center_x center_y  w h
-    float bbox[4];
-    float conf;  // bbox_conf * cls_conf
-    int class_id;
-    int index;
-};
-
-vector<Detection> results;
-/*-----------------------protobuf-------------------------*/
-iv::vision::Lightarray light_array;
-
-// stuff we know about the network and the input/output blobs
-static const int INPUT_H = 640;
-static const int INPUT_W = 640;
-static const int cls_num = 4;
-//不同输入尺寸anchor:960-->56700 | 640-->25200 | 416-->10647 | 320-->6300
-static const int anchor_output_num = 25200;
-static const int OUTPUT_SIZE = 1* anchor_output_num *(cls_num+5); //1000 * sizeof(Detection) / sizeof(float) + 1;
-
-
-const char* INPUT_BLOB_NAME = "images";
-const char* OUTPUT_BLOB_NAME = "output";
-
-
-
-//static Logger gLogger;
-
-//构建Logger
-class Logger : public ILogger
-{
-    void log(Severity severity, const char* msg) noexcept override
-    {
-        // suppress info-level messages
-        if (severity <= Severity::kWARNING)
-            std::cout << msg << std::endl;
-    }
-} gLogger;
-
-
-
-void doInference(IExecutionContext& context, float* input, float* output, int batchSize)
-{
-    const ICudaEngine& engine = context.getEngine();
-    // Pointers to input and output device buffers to pass to engine.
-    // Engine requires exactly IEngine::getNbBindings() number of buffers.
-    assert(engine.getNbBindings() == 2);
-    void* buffers[2];
-    // In order to bind the buffers, we need to know the names of the input and output tensors.
-    // Note that indices are guaranteed to be less than IEngine::getNbBindings()
-    const int inputIndex = engine.getBindingIndex(INPUT_BLOB_NAME);
-    const int outputIndex = engine.getBindingIndex(OUTPUT_BLOB_NAME);
-
-    //std::cout<<inputIndex<<" "<<outputIndex<<std::endl;
-    //const int inputIndex = 0;
-    //const int outputIndex = 1;
-    // Create GPU buffers on device
-    cudaMalloc(&buffers[inputIndex], batchSize * 3 * INPUT_H * INPUT_W * sizeof(float));
-    cudaMalloc(&buffers[outputIndex], batchSize * OUTPUT_SIZE * sizeof(float));
-    // Create stream
-    cudaStream_t stream;
-    CHECK(cudaStreamCreate(&stream));
-    // DMA input batch data to device, infer on the batch asynchronously, and DMA output back to host
-    CHECK(cudaMemcpyAsync(buffers[inputIndex], input, batchSize * 3 * INPUT_H * INPUT_W * sizeof(float), cudaMemcpyHostToDevice, stream));
-    context.enqueue(batchSize, buffers, stream, nullptr);
-
-    //std::cout<<buffers[outputIndex+1]<<std::endl;
-    CHECK(cudaMemcpyAsync(output, buffers[outputIndex], batchSize * OUTPUT_SIZE * sizeof(float), cudaMemcpyDeviceToHost, stream));
-    cudaStreamSynchronize(stream);
-    // Release stream and buffers
-    cudaStreamDestroy(stream);
-    CHECK(cudaFree(buffers[inputIndex]));
-    CHECK(cudaFree(buffers[outputIndex]));
-
-}
-
-
-
-//加工图片变成拥有batch的输入, tensorrt输入需要的格式,为一个维度
-void ProcessImage(cv::Mat image, float input_data[]) {
-    //只处理一张图片,总之结果为一维[batch*3*INPUT_W*INPUT_H]
-    //以下代码为投机取巧了
-
-    cv::resize(image, image, cv::Size(INPUT_W, INPUT_H), 0, 0, cv::INTER_LINEAR);
-    std::vector<cv::Mat> InputImage;
-
-    InputImage.push_back(image);
-
-
-
-    int ImgCount = InputImage.size();
-
-    //float input_data[BatchSize * 3 * INPUT_H * INPUT_W];
-    for (int b = 0; b < ImgCount; b++) {
-        cv::Mat img = InputImage.at(b);
-        int w = img.cols;
-        int h = img.rows;
-        int i = 0;
-        for (int row = 0; row < h; ++row) {
-            uchar* uc_pixel = img.data + row * img.step;
-            for (int col = 0; col < INPUT_W; ++col) {
-                input_data[b * 3 * INPUT_H * INPUT_W + i] = (float)uc_pixel[2] / 255.0;
-                input_data[b * 3 * INPUT_H * INPUT_W + i + INPUT_H * INPUT_W] = (float)uc_pixel[1] / 255.0;
-                input_data[b * 3 * INPUT_H * INPUT_W + i + 2 * INPUT_H * INPUT_W] = (float)uc_pixel[0] / 255.0;
-                uc_pixel += 3;
-                ++i;
-            }
-        }
-
-    }
-
-}
-
-
-
-
-//********************************************** NMS code **********************************//
-
-
-struct Bbox {
-    int x;
-    int y;
-    int w;
-    int h;
-};
-
-float iou(Bbox box1, Bbox box2) {
-
-    int x1 = max(box1.x, box2.x);
-    int y1 = max(box1.y, box2.y);
-    int x2 = min(box1.x + box1.w, box2.x + box2.w);
-    int y2 = min(box1.y + box1.h, box2.y + box2.h);
-    int w = max(0, x2 - x1);
-    int h = max(0, y2 - y1);
-    float over_area = w * h;
-    return over_area / (box1.w * box1.h + box2.w * box2.h - over_area);
-}
-
-int get_max_index(vector<Detection> pre_detection) {
-    //获得最佳置信度的值,并返回对应的索引值
-    int index;
-    float conf;
-    if (pre_detection.size() > 0) {
-        index = 0;
-        conf = pre_detection.at(0).conf;
-        for (int i = 0; i < pre_detection.size(); i++) {
-            if (conf < pre_detection.at(i).conf) {
-                index = i;
-                conf = pre_detection.at(i).conf;
-            }
-        }
-        return index;
-    }
-    else {
-        return -1;
-    }
-
-
-}
-bool judge_in_lst(int index, vector<int> index_lst) {
-    //若index在列表index_lst中则返回true,否则返回false
-    if (index_lst.size() > 0) {
-        for (int i = 0; i < index_lst.size(); i++) {
-            if (index == index_lst.at(i)) {
-                return true;
-            }
-        }
-    }
-    return false;
-}
-vector<int> nms(vector<Detection> pre_detection, float iou_thr)
-{
-    /*
-    返回需保存box的pre_detection对应位置索引值
-
-    */
-    int index;
-    vector<Detection> pre_detection_new;
-    //Detection det_best;
-    Bbox box_best, box;
-    float iou_value;
-    vector<int> keep_index;
-    vector<int> del_index;
-    bool keep_bool;
-    bool del_bool;
-    int rr = 0;
-    int zz = 0;
-
-    if (pre_detection.size() > 0) {
-
-        pre_detection_new.clear();
-        // 循环将预测结果建立索引
-        for (int i = 0; i < pre_detection.size(); i++) {
-            pre_detection.at(i).index = i;
-            pre_detection_new.push_back(pre_detection.at(i));
-        }
-        //循环便利获得保留box位置索引-相对输入pre_detection位置
-        while (pre_detection_new.size() > 0) {
-            index = get_max_index(pre_detection_new);
-            if (index >= 0) {
-                keep_index.push_back(pre_detection_new.at(index).index); //保留索引位置
-
-                // 更新最佳保留box
-                box_best.x = pre_detection_new.at(index).bbox[0];
-                box_best.y = pre_detection_new.at(index).bbox[1];
-                box_best.w = pre_detection_new.at(index).bbox[2];
-                box_best.h = pre_detection_new.at(index).bbox[3];
-
-                for (int j = 0; j < pre_detection.size(); j++) {
-                    keep_bool = judge_in_lst(pre_detection.at(j).index, keep_index);
-                    del_bool = judge_in_lst(pre_detection.at(j).index, del_index);
-                    if ((!keep_bool) && (!del_bool)) { //不在keep_index与del_index才计算iou
-                        box.x = pre_detection.at(j).bbox[0];
-                        box.y = pre_detection.at(j).bbox[1];
-                        box.w = pre_detection.at(j).bbox[2];
-                        box.h = pre_detection.at(j).bbox[3];
-                        iou_value = iou(box_best, box);
-                        if (iou_value > iou_thr) {
-                            del_index.push_back(j); //记录大于阈值将删除对应的位置
-                        }
-                    }
-
-                }
-                //更新pre_detection_new
-                pre_detection_new.clear();
-                for (int j = 0; j < pre_detection.size(); j++) {
-                    keep_bool = judge_in_lst(pre_detection.at(j).index, keep_index);
-                    del_bool = judge_in_lst(pre_detection.at(j).index, del_index);
-                    if ((!keep_bool) && (!del_bool)) {
-                        pre_detection_new.push_back(pre_detection.at(j));
-                    }
-                }
-            }
-        }
-    }
-
-    del_index.clear();
-    del_index.shrink_to_fit();
-    pre_detection_new.clear();
-    pre_detection_new.shrink_to_fit();
-
-    return  keep_index;
-
-}
-
-
-
-
-
-vector<Detection>  postprocess(float* prob, float conf_thr = 0.2, float nms_thr = 0.4) {
-    /*
-    #####################此函数处理一张图预测结果#########################
-    prob为[x y w h  score  multi-pre] 如80类-->(1,anchor_num,85)
-
-    */
-
-    vector<Detection> pre_results;
-    vector<int> nms_keep_index;
-    vector<Detection> results;
-    bool keep_bool;
-    Detection pre_res;
-    float conf;
-    int tmp_idx;
-    float tmp_cls_score;
-    for (int i = 0; i < anchor_output_num; i++) {
-        tmp_idx = i * (cls_num + 5);
-        pre_res.bbox[0] = prob[tmp_idx + 0];
-        pre_res.bbox[1] = prob[tmp_idx + 1];
-        pre_res.bbox[2] = prob[tmp_idx + 2];
-        pre_res.bbox[3] = prob[tmp_idx + 3];
-        conf = prob[tmp_idx + 4];  //是为目标的置信度
-        tmp_cls_score = prob[tmp_idx + 5] * conf;
-        pre_res.class_id = 0;
-        pre_res.conf = tmp_cls_score;
-        for (int j = 1; j < cls_num; j++) {
-            tmp_idx = i * (cls_num + 5) + 5 + j; //获得对应类别索引
-            if (tmp_cls_score < prob[tmp_idx] * conf)
-            {
-                tmp_cls_score = prob[tmp_idx] * conf;
-                pre_res.class_id = j;
-                pre_res.conf = tmp_cls_score;
-            }
-        }
-        if (conf >= conf_thr) {
-
-            pre_results.push_back(pre_res);
-        }
-
-    }
-
-    //使用nms
-    nms_keep_index=nms(pre_results,nms_thr);
-
-    for (int i = 0; i < pre_results.size(); i++) {
-        keep_bool = judge_in_lst(i, nms_keep_index);
-        if (keep_bool) {
-            results.push_back(pre_results.at(i));
-        }
-
-    }
-
-
-    pre_results.clear();
-    pre_results.shrink_to_fit();
-    nms_keep_index.clear();
-    nms_keep_index.shrink_to_fit();
-
-
-    return results;
-
-}
-
-cv::Mat draw_rect(cv::Mat image, vector<Detection> results) {
-    /*
-    image 为图像
-
-    struct  Detection {
-    float bbox[4];  //center_x center_y  w h
-    float conf;  // 置信度
-    int class_id; //类别id
-    int index;    //可忽略
-    };
-
-    */
-
-    float x;
-    float y;
-    float w;
-    float h;
-    string info;
-
-    cv::Rect rect;
-    for (int i = 0; i < results.size(); i++) {
-
-        x = results.at(i).bbox[0];
-        y= results.at(i).bbox[1];
-        w= results.at(i).bbox[2];
-        h=results.at(i).bbox[3];
-
-        /*---------------protobuf----------------*/
-        iv::vision::Light *light = light_array.add_light();
-        light->set_index(i+1);
-        light->set_type(results.at(i).class_id+1);
-
-        /*----------------------------------------*/
-
-
-        x = (int)(x - w / 2);
-        y = (int)(y - h / 2);
-        w = (int)w;
-        h = (int)h;
-        info = "id:";
-        info.append(to_string(results.at(i).class_id));
-        info.append(" s:");
-        info.append(to_string((int)(results.at(i).conf*100)  )   );
-        info.append("%");
-        rect= cv::Rect(x, y, w, h);
-        if(results.at(i).class_id == 0){ // red light
-            cv::rectangle(image, rect, cv::Scalar(0, 0, 255), 2, 1, 0);//矩形的两个顶点,两个顶点都包括在矩形内部
-            cv::putText(image, info, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(0, 0, 255), 0.6, 1, false);
-        }else if(results.at(i).class_id == 1){ // green light
-            cv::rectangle(image, rect, cv::Scalar(0, 255, 0), 2, 1, 0);//矩形的两个顶点,两个顶点都包括在矩形内部
-            cv::putText(image, info, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(0, 255, 0), 0.6, 1, false);
-        }else if(results.at(i).class_id == 2){ // yellow light
-            cv::rectangle(image, rect, cv::Scalar(0, 255, 255), 2, 1, 0);//矩形的两个顶点,两个顶点都包括在矩形内部
-            cv::putText(image, info, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(0, 255, 255), 0.6, 1, false);
-        }else{
-            cv::rectangle(image, rect, cv::Scalar(255, 255, 255), 2, 1, 0);//矩形的两个顶点,两个顶点都包括在矩形内部
-            cv::putText(image, info, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(255, 255, 255), 0.6, 1, false);
-        }
-//        cv::rectangle(image, rect, cv::Scalar(0, 255, 0), 1, 1, 0);//矩形的两个顶点,两个顶点都包括在矩形内部
-//        cv::putText(image, info, cv::Point(x, y), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(0, 255, 0), 0.4, 1, false);
-
-    }
-
-
-    return image;
-
-}
-
-void LoadEngine(const std::string engine_path){
-    //加载engine引擎
-    char* trtModelStream{ nullptr };
-    size_t size{ 0 };
-    std::ifstream file(engine_path, std::ios::binary);
-    if (file.good()) {
-        file.seekg(0, file.end);
-        size = file.tellg();
-        file.seekg(0, file.beg);
-        trtModelStream = new char[size];
-        assert(trtModelStream);
-        file.read(trtModelStream, size);
-        file.close();
-    }
-
-    //反序列为engine,创建context
-
-    runtime = createInferRuntime(gLogger);
-    assert(runtime != nullptr);
-    engine = runtime->deserializeCudaEngine(trtModelStream, size, nullptr);
-    assert(engine != nullptr);
-    context = engine->createExecutionContext();
-    assert(context != nullptr);
-    delete[] trtModelStream;
-
-    //在主机上分配页锁定内存
-    CHECK(cudaHostAlloc((void **)&prob, OUTPUT_SIZE * sizeof(float), cudaHostAllocDefault));
-}
-
-void shareMsg(){
-    int size = light_array.ByteSize();
-    char * strdata = new char[light_array.ByteSize()];
-    if(light_array.SerializeToArray(strdata, size))
-    {
-        iv::modulecomm::ModuleSendMsg(gpdetect, strdata, size);
-    }
-    else
-    {
-        std::cout<<"light_array serialize error."<<std::endl;
-    }
-    light_array.Clear();
-    delete strdata;
-
-    /*--------------------test ParseFromArray-------------------*/
-//    iv::vision::Lightarray light_array1;
-//    light_array1.ParseFromArray(strdata,size);
-//    cout<<"parsefromarray:"<<std::endl;
-//    cout<<"light_size:"<<light_array1.light_size()<<endl;
-//    for (int i=0;i<light_array1.light_size();i++) {
-//        std::cout<<"index:"<<light_array1.light(i).index()<<" type:"
-//                <<light_array1.light(i).type()
-//                <<std::endl;
-
-//    }
-}
-
-void infer(cv::Mat img) {
-
-   // 处理图片为固定输出
-
-    auto start = std::chrono::system_clock::now();  //时间函数
-    static float data[3 * INPUT_H * INPUT_W];
-
-    ProcessImage(img, data);
-    auto end = std::chrono::system_clock::now();
-    time_read_img = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() + time_read_img;
-
-//    cout<<"read img time: "<<time_read_img<<"ms"<<endl;
-    //Run inference
-    start = std::chrono::system_clock::now();  //时间函数
-    doInference(*context, data, prob, 1);
-    cout<<"doinference"<<endl;
-    end = std::chrono::system_clock::now();
-    time_infer = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() + time_infer;
-    std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;
-
-    //输出后处理
-    //std::cout <<"prob="<<prob << std::endl;
-    results.clear();
-    results=postprocess(prob, 0.3,  0.4);
-
-    cv::resize(img, img, cv::Size(INPUT_W, INPUT_H), 0, 0, cv::INTER_LINEAR);
-    res_img=draw_rect(img,results);
-
-//    cv::imshow("streetLight", res_img);
-//    cv::waitKey(1);
-
-    cout << "ok" << endl;
-    time_num++;
-    shareMsg();
-
-}
-
-
-
-void exitfunc()
-{
-    return;
-}
-
-void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
-{
-
-    std::cout<<"one time"<<std::endl;
-    if(nSize<1000)return;
-    iv::vision::rawpic pic;
-
-    if(false == pic.ParseFromArray(strdata,nSize))
-    {
-        std::cout<<"picview Listenpic fail."<<std::endl;
-        return;
-    }
-
-    cv::Mat mat(pic.height(),pic.width(),pic.mattype());
-    if(pic.type() == 1)
-        memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
-    else
-    {
-       mat.release();
-       std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
-       mat = cv::imdecode(buff,CV_LOAD_IMAGE_COLOR);
-    }
-
-    cv::Mat img_camera=mat;
-
-//    img_camera = img_camera(cv::Range(0,640), cv::Range(320,960));//height width
-//    img_camera = img_camera(cv::Range(240,600), cv::Range(320,960));
-    img_camera = img_camera(cv::Range(240,600), cv::Range(460,820));
-//    cv::remap(img_camera,img_camera,map1,map2,cv::INTER_LINEAR,cv::BORDER_CONSTANT);
-
-    infer(img_camera);
-
-    mat.release();
-}
-
-void ListenLight(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
-{
-
-    std::cout<<"one time"<<std::endl;
-    if(nSize<1000)return;
-    iv::vision::rawpic pic;
-    iv::brain::brainstate brain_state;
-
-    if(false == brain_state.ParseFromArray(strdata,nSize))
-    {
-        std::cout<<"brain_state Listen fail."<<std::endl;
-        return;
-    }
-
-    cv::Mat mat(pic.height(),pic.width(),pic.mattype());
-    if(pic.type() == 1)
-        memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
-    else
-    {
-       mat.release();
-       std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
-       mat = cv::imdecode(buff,CV_LOAD_IMAGE_COLOR);
-    }
-
-    cv::Mat img_camera=mat;
-
-//    img_camera = img_camera(cv::Range(0,640), cv::Range(320,960));//height width
-//    img_camera = img_camera(cv::Range(240,600), cv::Range(320,960));
-    img_camera = img_camera(cv::Range(240,600), cv::Range(460,820));
-//    cv::remap(img_camera,img_camera,map1,map2,cv::INTER_LINEAR,cv::BORDER_CONSTANT);
-
-    infer(img_camera);
-
-    mat.release();
-}
-
-int main(int argc, char** argv)
-{
-    showversion("yolov5s");
-    QCoreApplication a(argc, argv);
-
-    gfault = new iv::Ivfault("lidar_cnn_segmentation");
-    givlog = new iv::Ivlog("lidar_cnn_segmentation");
-    gfault->SetFaultState(0,0,"cnn initialize.");
-
-
-//================================== camera calib init ==========================
-
-    cv::FileStorage calib_file("/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/yaml/camera_middle_640_360.yaml", cv::FileStorage::READ);
-    calib_file["cameraMatrix"]>>camera_matrix;
-    calib_file["distCoeffs"]>>dist_coe;
-    cv::Mat R = cv::Mat::eye(3, 3, CV_64F);
-    cv::Size imgsize=cv::Size(640,360);
-    cv::initUndistortRectifyMap(camera_matrix, dist_coe, R, camera_matrix,imgsize,CV_16SC2,map1,map2);
-
-//==============================================================================
-
-    bool light_start = false;
-    while(light_start == false){
-        light_start = iv::modulecomm::RegisterRecv("lightStart",ListenLight);
-    }
-
-
-    LoadEngine(engine_path);
-    gp = iv::modulecomm::RegisterRecv("image00",Listenpic);
-    gpdetect = iv::modulecomm::RegisterSend("streetLight",10000000,1);
-
-//==============================================================================================
-//    cv::Mat img_test = cv::imread("/home/nvidia/modularization/src/detection/yolov5-trt/data/00002.jpg");
-//    infer(img_test);
-//    while(true){
-//        cv::imshow("streetLight", res_img);
-//        cv::waitKey(10);
-//    }
-//==========================================================================================
-    cv::VideoCapture cap("/home/nvidia/code/modularization/src/detection/yolov5-trt-v2.0/data/phone_light1.mp4");
-    if(!cap.isOpened()){
-        std::cout<<"open failed"<<std::endl;
-        return -1;
-    }
-    cv::Mat frame;
-    cv::waitKey(1000);
-    while(true){
-        cap>>frame;
-        if(frame.empty()){
-            break;
-        }
-        //frame = frame(cv::Range(240,480), cv::Range(520,760));//height width
-        //frame = frame(cv::Range(0,640), cv::Range(320,960));//height width
-        //frame = frame(cv::Range(240,600), cv::Range(320,960));//height width
-
-        frame = frame(cv::Range(0,640), cv::Range(320,980));//height width
- //        cv::remap(frame,frame,map1,map2,cv::INTER_LINEAR,cv::BORDER_CONSTANT);
-        //infer(frame);
-        cv::imshow("streetLight", frame);
-        if (cv::waitKey(10) == 'q') break;
-    }
-    cv::destroyAllWindows();
-
-//========================================================================================
-//    cv::waitKey(5000);
-//    while(true){
-//        cv::imshow("streetLight", res_img);
-//        cv::waitKey(10);
-//    }
-    std::cout << "C++ 2engine" << " mean read img time =" << time_read_img / time_num << "ms\t" << " mean infer img time =" << time_infer / time_num << "ms" << std::endl;
-
-    // Destroy the engine
-    context->destroy();
-    engine->destroy();
-    runtime->destroy();
-
-    return 0;
-}
-

+ 0 - 12
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/camera.yaml

@@ -1,12 +0,0 @@
-%YAML:1.0
-
-cameraMatrix:
-    rows: 3
-    cols: 3
-    dt: f
-    data: [329.8960137714725, 0.0, 306.98655702722937, 0.0, 329.8476481330821, 147.92102146061933, 0.0, 0.0, 1.0]
-distCoeffs: 
-    rows: 1
-    cols: 4
-    dt: f
-    data: [0.06540082256039308, 0.003679070986049775, 0.02795206257493852, 0.019310323874426313]

+ 0 - 12
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/camera_ori.yaml

@@ -1,12 +0,0 @@
-%YAML:1.0
-
-cameraMatrix:
-    rows: 3
-    cols: 3
-    dt: f
-    data: [283.2175041932327, 0.0, 618.5248476440728, 0.0, 282.8089524514217, 386.63584727262344, 0.0, 0.0, 1.0]
-distCoeffs: 
-    rows: 1
-    cols: 4
-    dt: f
-    data: [0.1362060349662609,-0.027120543730038277,0.16273833878800492,-0.16242892318961671]

+ 0 - 16
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/init.yaml

@@ -1,16 +0,0 @@
-source:
-- 0
-
-src:
-- [140, 370]
-- [220, 298]
-- [410, 292]
-- [478, 360]
-dst:
-- [125, 371]
-- [125, 218]
-- [484, 218]
-- [484, 370]
-
-meters: 2.0
-pixels: 640

+ 0 - 19
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers.yaml

@@ -1,19 +0,0 @@
-%YAML:1.0
-
-
-board_left_top: [255,189]
-
-board_left_bottom: [193,232]
-
-board_right_top: [342,189]
-
-board_right_bottom: [403,232]
-
-
-board_left_top_dst: [569,409]
-
-board_left_bottom_dst: [569,504]
-
-board_right_top_dst: [635,409]
-
-board_right_bottom_dst: [635,504]

+ 0 - 19
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers3.yaml

@@ -1,19 +0,0 @@
-%YAML:1.0
-
-
-board_left_top: [569,459]
-
-board_left_bottom: [509,504]
-
-board_right_top: [635,459]
-
-board_right_bottom: [696,504]
-
-
-board_left_top_dst: [569,409]
-
-board_left_bottom_dst: [569,504]
-
-board_right_top_dst: [635,409]
-
-board_right_bottom_dst: [635,504]

+ 0 - 19
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers_1.yaml

@@ -1,19 +0,0 @@
-%YAML:1.0
-
-
-board_left_top: [569,459]
-
-board_left_bottom: [509,504]
-
-board_right_top: [635,459]
-
-board_right_bottom: [696,504]
-
-
-board_left_top_dst: [509,459]
-
-board_left_bottom_dst: [509,550]
-
-board_right_top_dst: [635,459]
-
-board_right_bottom_dst: [635,550]

+ 0 - 19
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers_2.yaml

@@ -1,19 +0,0 @@
-%YAML:1.0
-
-
-board_left_top: [126,276]
-
-board_left_bottom: [33,312]
-
-board_right_top: [206,276]
-
-board_right_bottom: [273,312]
-
-
-board_left_top_dst: [200,100]
-
-board_left_bottom_dst: [200,800]
-
-board_right_top_dst: [900,100]
-
-board_right_bottom_dst: [900,800]

+ 0 - 10
src/detection/yolov5-trt-v2.0/yaml_bak_zhengke/pers_ori.yaml

@@ -1,10 +0,0 @@
-%YAML:1.0
-
-
-board_left_top: [283,352]
-
-board_left_bottom: [269,406]
-
-board_right_top: [353,352]
-
-board_right_bottom: [363,406]