派生自 Algorithm/baseDetector

Scheaven
2021-07-27 5e878ed96fe6c05b88f7978f50d73a16f4b8a65e
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
//
// Created by Scheaven on 2020/3/23.
//
 
#include "ari_manager.h"
 
 
AriManager::AriManager()
{
    Config config;
    // config.net_type = COMMON;
    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);
}
 
AriManager::~AriManager()
{
 
}
 
void AriManager::single_SDK(const int cam_id, const void *img, TResult& t_result)
{
    TImage *frame_img = (TImage*)img;
    cv::Mat frame(Size(frame_img->width, frame_img->height), CV_8UC3);
    frame.data = (uchar*)frame_img->data;
 
    std::vector<bbox_t> result_vec;
 
    std::vector<BatchResult> batch_res;
    std::vector<cv::Mat> batch_img;
 
    // cv::Mat image0 = cv::imread("/data/disk1/project/03_tensorRT/yolo-tensorrt/configs/dog.jpg", cv::IMREAD_UNCHANGED);
    // cv::Mat image1 = cv::imread("/data/disk1/project/03_tensorRT/yolo-tensorrt/configs/person.jpg", cv::IMREAD_UNCHANGED);
    batch_img.push_back(frame.clone());
    // batch_img.push_back(image1.clone());
    // batch_img.push_back(image1.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image0.clone());
    // batch_img.push_back(image1.clone());
 
    // cv::imshow("img",image0);
    // cv::waitKey(0);
    Timer timer;
    timer.reset();
    this->detector->detect(batch_img, batch_res);
    timer.out("detect");
 
    t_result.targets = (Target*)malloc(sizeof(Target)*batch_res[0].size());
    // 将算法结果转化为标准的格式(以目标检测为例)
    int w_count = 0;
    for (const auto &result_box:batch_res[0])
    {
        // if(result_box.id == 0)
        // {
            Target target;
            init_target(&target);
 
            target.rect.left = result_box.rect.x;
            target.rect.top =  result_box.rect.y;
            target.rect.right =  result_box.rect.x + result_box.rect.width;
            target.rect.bottom = result_box.rect.y + result_box.rect.height;
 
            target.confidence = result_box.prob*100;  // 置信度转化成百分制
            // target.id = 1; //
 
            //  target.attribute 可根据实际情况来添加,输出格式要求是json格式
 
            //string attribute_json = "{";
            //attribute_json += "\"smokingScore\":" + to_string(track->smokeScore)+",";
            //if(attribute_json.length()>2)
            //{
            //    attribute_json = attribute_json.substr(0, attribute_json.length()-1) +"}";
            //    target.attribute = new char[strlen(attribute_json.c_str())+1];
            //    target.attribute_size = strlen(attribute_json.c_str());
            //    strcpy(target.attribute, attribute_json.c_str());
            //}
 
            t_result.targets[w_count] = target;
            w_count ++;
        // }
    }
    t_result.count = w_count;
}
 
void AriManager::init_target(Target *t){
    t->attribute = NULL;
    t->feature = NULL;
    t->id = 0;
    t->rect = TRect{0,0,0,0};
    t->confidence = 0;
    t->attribute_size = 0;
    t->feature_size = 0;
}