-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolov5.h
62 lines (48 loc) · 1.46 KB
/
yolov5.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
#ifndef YOLOV5_H_
#define YOLOV5_H_
#include <chrono>
#include <cmath>
#include <iostream>
#include <inference_engine.hpp>
#include <opencv2/dnn/dnn.hpp>
#include <opencv2/opencv.hpp>
namespace yolov5 {
struct Object {
cv::Rect_<float> rect;
int label;
float prob;
};
class Yolov5 {
public:
Yolov5(std::string xml_path, float conf_thresh, float nms_thresh,
int height, int width);
std::vector<Object> Detect(cv::Mat& img);
private:
cv::Mat Resize(cv::Mat& img);
std::vector<Object> GenerateProposals(std::vector<float>& anchors,
int stride,
const InferenceEngine::Blob::Ptr &blob);
int Draw(cv::Mat& rgb, const std::vector<Object>& objects);
const std::string xml_path_;
const float conf_thresh_;
const float obj_score_thresh_;
const float nms_thresh_;
std::vector<std::vector<float>> anchors_;
const int height_;
const int width_;
float scale_;
std::string input_name_;
InferenceEngine::ExecutableNetwork network_;
InferenceEngine::OutputsDataMap outputinfo_;
};
inline std::chrono::steady_clock::time_point Now() {
return std::chrono::steady_clock::now();
}
inline std::chrono::duration<double>::rep Duration(
const std::chrono::steady_clock::time_point& t2,
const std::chrono::steady_clock::time_point& t1) {
std::chrono::duration<double> interval = t2 - t1;
return interval.count();
}
} // namespace yolov5
#endif // YOLOV5_H_