DetectorYOLOV3.h 1.29 KB
Newer Older
lijian6's avatar
lijian6 committed
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
// YOLOV3检测器
#ifndef __DETECTOR_YOLOV3_H__
#define __DETECTOR_YOLOV3_H__

#include <string>
#include <fstream>
#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include "CommonUtils.h"
#include "Queuethread.h"
#include "Decoder.h"

using namespace std;
using namespace cv;

typedef struct  _ResultOfDetection
{
    Rect boundingBox;
    float confidence;
    int classID;
    string className;
    bool exist;

    _ResultOfDetection():confidence(0.0f),classID(0),exist(true){}

}ResultOfDetection;

class DetectorYOLOV3
{
public:
    ~DetectorYOLOV3();

    void setNumThread(int numOfThread);

    void setGpuIndex(int gpuIndex);

    void initModel(const std::string &pathStr, const std::string &pathOfClassNameFile);

    void Detect(cv::Mat srcImage);

private:
    Ort::Session *session;
    Ort::Env env = Ort::Env(ORT_LOGGING_LEVEL_ERROR, "Yolov3");
    Ort::SessionOptions sessionOptions = Ort::SessionOptions();
    int numThread = 0;
    vector<string> classNames;

    std::vector<int64_t> inputDim;
    std::vector<Ort::AllocatedStringPtr> inputNamesPtr;
    std::vector<Ort::AllocatedStringPtr> outputNamesPtr;

    const float meanValues[3] = {0, 0, 0};
    const float normValues[3] = {1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0};
};


#endif