-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDetector.h
76 lines (57 loc) · 1.66 KB
/
Detector.h
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
#pragma once
#include<iostream>
#include<string>
#include<cmath>
#include<time.h>
#include<algorithm>
#include <numeric>
#include"NvInfer.h"
#include"NvOnnxParser.h"
#include"Utils.h"
#include"EntropyCalibrator.h"
#include<cudnn.h>
#include<opencv2/opencv.hpp>
#include<chrono>
static const int INPUT_CHANNEL=3; // =1 detect with grey image
static const int CHECK_COUNT = 3; // output achor box for each yolo layer
static const int BATCH_SIZE = 1;
struct YoloKernel
{
int width;
int height;
float anchors[CHECK_COUNT*2];
};
struct Detection
{
float bbox[4];
int classId;
float prob;
};
class Detector{
public:
Detector(std::string onnxFile,std::string trtFile,std::string calibFileList,int input_w,int input_h,int num_classes,float yolo_thresh,float nms_thresh,bool use_int8);
~Detector();
std::vector<std::vector<Detection>> doInference(std::vector<cv::Mat>& img);
private:
void postProcessImg(cv::Mat& img,std::vector<Detection>& detections);
void doNms(std::vector<Detection>& detections,float nmsThresh);
std::vector<std::vector<Detection>>interpretOutputTensor(float *tensor,int batchSize);
Logger logger_;
nvinfer1::IExecutionContext* context_;
nvinfer1::ICudaEngine* engine_;
nvinfer1::IRuntime* runtime_;
std::unique_ptr<float[]> inputData_;
std::unique_ptr<float[]> outputData_;
cudaStream_t stream_;
std::unique_ptr<void*[]> buffers_;
std::vector<YoloKernel> yoloKernel_;
// param
int inputW_;
int inputH_;
int numClasses_;
float yoloThresh_;
float nmsThresh_;
const YoloKernel yolo1_;
const YoloKernel yolo2_;
const YoloKernel yolo3_;
};