派生自 Algorithm/baseDetector

sunty
2022-03-21 d0a24896f95b4e060011852f80048ebfb0bf5f55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// Created by Scheaven on 2019/11/19.
//
 
#include "detecter_manager.h"
#include <thread>
#include <unistd.h>
#include <cstdlib>
 
DetecterManager* DetecterManager::instance = NULL;
 
DetecterManager* DetecterManager::getInstance()
{
    if(instance==NULL)
    {
        instance = new DetecterManager();
    }
    return instance;
}
 
DetecterManager::DetecterManager()
{
    Config config;
    config.net_type = YOLOV4;
    config.file_model_cfg = m_staticStruct::model_cfg;
    config.file_model_weights = m_staticStruct::model_wts;
    config.calibration_image_list_file_txt = "../configs/calibration_images.txt";
    config.inference_precison = INT8;
    config.detect_thresh = 0.5;
 
    //if(m_staticStruct::type==2)
    //    config.net_type = SMALL;
    //else
    //    config.net_type = COMMON;
 
 
    this->detector = std::shared_ptr<Detector>(new Detector());
    this->detector->init(config);
    std::cout << "loading detector model......" << std::endl;
}
 
 
DetecterManager::~DetecterManager()
{
}
 
void DetecterManager::release()
{
    // Detector::getInstance()->release();
 
    delete DetecterManager::instance;
    DetecterManager::instance = NULL;
}
 
void DetecterManager::detecter_main(cv::Mat &mat_image, DETECTIONS& detection)
{
    std::vector<BatchResult> batch_res;
    std::vector<cv::Mat> batch_img;
 
    batch_img.push_back(mat_image.clone());
    this->detector->detect(batch_img, batch_res);
    encoder_features(batch_res, detection);
 
  //  show_result(result_vec);
//    draw_boxes(mat_image, result_vec);
}
 
void DetecterManager::encoder_features(std::vector<BatchResult> boxes,  DETECTIONS &detection)
{
    std::vector<float> confidences;
    std::vector<int> human_index;
 
    int result_index=0;
 
    for (const auto &result_box:boxes[0])
    {
//        #ifdef S_DEBUG
//                printf("--%d-%d-%d-%d-%d---result_box-----\n", result_box.obj_id, result_box.x, result_box.y, result_box.w, result_box.h);
//        #endif
        if(result_box.id == 1)
        {
            // cv::Rect box = cv::Rect(result_box.x,result_box.y,result_box.w,result_box.h);
            // get_detections(DETECTBOX(box.x, box.y,box.width,  box.height), confidences[idx],d);
            DETECTION_ROW tmpRow;
            tmpRow.tlwh = DETECTBOX(result_box.rect.x,result_box.rect.y,result_box.rect.width,result_box.rect.height); //DETECTBOX(x, y, w, h);
            tmpRow.confidence = result_box.prob*100;
            tmpRow.obj_id = 0;
            tmpRow.is_hat = true;
            tmpRow.is_mask = true;
            tmpRow.is_smoke = true;
            tmpRow.hatScore = 0;
            tmpRow.maskScore = 0;
            tmpRow.smokeScore = 0;
            // tmpRow.img_time = this->img_time;
 
            tmpRow.isFall = false;
            tmpRow.fallScore = 0;
            tmpRow.runScore = 0;
            tmpRow.isRun = false;
 
//            tmpRow.human_face = nullptr;
 
            int sub_box_index=0;
            human_index.push_back(result_index);
 
            detection.push_back(tmpRow);
        }
        result_index++;
    }
}
 
// bool DetecterManager::sort_score(bbox_t box1, bbox_t box2)
// {
//     return (box1.prob>box2.prob);
// }
 
// float DetecterManager::box_iou(bbox_t box1, bbox_t box2)
// {
//     int x1 = std::max(box1.x, box2.x);
//     int y1 = std::max(box1.y, box2.y);
//     int x2 = std::min((box1.x+box1.w),(box2.x+box2.w));
//     int y2 = std::min((box1.y+box1.h),(box2.y+box2.h));
//     float over_area = (x2-x1)*(y2-y1);
// //    printf("over_ares---%f ----%d----%d\n", over_area, box1.w*box1.h, box2.w*box2.h);
//     float iou = over_area/((box1.w*box1.h<box2.w*box2.h)?box1.w*box1.h:box2.w*box2.h);
//     return iou;
// }
 
void DetecterManager::set_imgTime(long img_time)
{
    this->img_time = img_time;
}