派生自 Algorithm/baseDetector

孙天宇
2022-07-12 ce9d187fd294cca192a27f52719094e9df7b1b62
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
#ifndef DETECTOR_H
#define DETECTOR_H
#include <iostream>
#include <opencv2/opencv.hpp>
#include "config.h"
#include <experimental/filesystem>
#include <fstream>
#include <string>
#include <chrono>
#include <stdio.h>
#include "model.h"
 
 
struct Result
{
    int      id     = -1;
    float    prob   = 0.f;
    cv::Rect rect;
};
 
using BatchResult = std::vector<Result>;
 
enum ModelType
{
    COMMON,
    SMALL
};
 
enum Precision
{
    INT8 = 0,
    FP16,
    FP32
};
 
struct Config
{
    float detect_thresh                         = 0.1;
 
    Precision   inference_precison              = FP32;
 
    ModelType   net_type                        = COMMON;
 
    int gpu_id                                  = 0;
};
 
class Detector
{
private:
    Config _config;
    NetworkInfo _info;
    InferParams _infer_param;
    std::vector<std::string> _vec_net_type{ "common","small"};
    std::vector<std::string> _vec_precision{ "kINT8","kHALF","kFLOAT" };
    std::unique_ptr<Detecter> _p_net = nullptr;
    Timer _m_timer;
 
 
 
public:
    Detector();
    ~Detector();
 
    void init(const Config &config);
    void detect(const std::vector<cv::Mat>  &vec_image,
                std::vector<BatchResult> &vec_batch_result);
 
private:
    void set_gpu_id(const int id=0);
 
    void parse_config();
 
    void build_net();
 
    // std::vector<BBoxInfo> decodeTensor(const int imageIdx, const int imageH, const int imageW, const TensorInfo& tensor) override;
};
 
#endif