-
Notifications
You must be signed in to change notification settings - Fork 6
/
smoke.hpp
74 lines (64 loc) · 1.85 KB
/
smoke.hpp
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
#pragma once
#include <iostream>
#include <NvInfer.h>
#include <opencv2/core.hpp>
class Logger : public nvinfer1::ILogger {
public:
explicit Logger(Severity severity = Severity::kWARNING)
: reportable_severity(severity) {}
void log(Severity severity, const char* msg) noexcept {
if (severity > reportable_severity) {
return;
}
switch (severity) {
case Severity::kINTERNAL_ERROR:
std::cerr << "INTERNAL_ERROR: ";
break;
case Severity::kERROR:
std::cerr << "ERROR: ";
break;
case Severity::kWARNING:
std::cerr << "WARNING: ";
break;
case Severity::kINFO:
std::cerr << "INFO: ";
break;
default:
std::cerr << "UNKNOWN: ";
break;
}
std::cerr << msg << std::endl;
}
Severity reportable_severity;
};
struct BboxDim {
float x;
float y;
float z;
};
class SMOKE {
public:
SMOKE();
SMOKE(const std::string& engine_path, const cv::Mat& intrinsic);
~SMOKE();
void Detect(const cv::Mat& raw_img);
void LoadOnnx(const std::string& onnx_path);
void LoadEngine(const std::string& engine_path);
void prepare(const cv::Mat& intrinsic);
private:
void PostProcess(cv::Mat& input_img);
Logger g_logger_;
cudaStream_t stream_;
nvinfer1::IHostMemory* plan_;
nvinfer1::ICudaEngine* engine_;
nvinfer1::IExecutionContext* context_;
void* buffers_[4];
int buffer_size_[4];
std::vector<float> image_data_;
std::vector<float> bbox_preds_;
std::vector<float> topk_scores_;
std::vector<float> topk_indices_;
cv::Mat intrinsic_;
std::vector<float> base_depth_;
std::vector<BboxDim> base_dims_;
};