-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnnxInstance.h
More file actions
75 lines (56 loc) · 1.84 KB
/
OnnxInstance.h
File metadata and controls
75 lines (56 loc) · 1.84 KB
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
#pragma once
#include "OnnxModel.h"
#include <obs.h>
#include <obs-module.h>
#include <string>
#include <opencv2/core/types.hpp>
#include <onnxruntime_cxx_api.h>
#include <cpu_provider_factory.h>
class OnnxInstance;
class Onnx
{
public:
static Onnx &instance()
{
static Onnx a;
return a;
}
OnnxInstance* get(obs_source_t *source);
void registerIncrementSource(obs_source_t *source);
void unregisterDeIncrementSource(obs_source_t *source);
private:
Onnx() = default;
Onnx(const Onnx &) = delete;
Onnx &operator=(const Onnx &) = delete;
private:
// int is a ++, -- counter at each registration. A source might be using the same onnx instance from 5 filters or something like that
std::map<obs_source_t*, std::pair<int, std::unique_ptr<OnnxInstance>>> m_instances;
};
class OnnxInstance
{
friend class Onnx;
public:
OnnxInstance();
~OnnxInstance();
public:
void init(const std::wstring& onnxModelPath);
bool update(obs_source_t *source, gs_texrender_t *texrender, gs_stagesurf_t *stagesurface, const std::vector<OnnxModel::Category>& cats);
public:
uint32_t m_maskWidth = 0;
uint32_t m_maskHeight = 0;
uint64_t m_lastUpdate = 0;
clock_t m_lastModelRun = 0;
// This needs to match for all segm categories
float m_temporalSmoothFactor = 0.5f;
// Inference / Model configuration
std::unique_ptr<OnnxModel> m_model;
// Frame data
std::map<OnnxModel::Category, cv::Mat> m_lastSmallMask;
std::map<OnnxModel::Category, cv::Mat> m_lastFullMask;
std::map<OnnxModel::Category, cv::Mat> m_lastFullBGRA;
std::map<OnnxModel::Category, cv::Mat> m_lastOnnxOutput;
private:
bool getRGBAFromStageSurface(gs_texrender_t*& texrender, gs_stagesurf_t*& stagesurface, obs_source_t* source, uint32_t& width, uint32_t& height, cv::Mat& outputBGRA);
};
#define MASK_EFFECT_PATH "mask_alpha_filter.effect"
#define KAWASE_BLUR_EFFECT_PATH "kawase_blur.effect"