-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.h
111 lines (75 loc) · 1.82 KB
/
prepare.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// Created by nhk on 18-8-19.
///initialize
//选定object区域
///update
//确定obj区域与bkg区域的直方图
//在新的一帧中计算每个像素点标记到S或T的惩罚项
//计算邻域像素间不连续惩罚
//最大流最小割求解obj区域
//
#ifndef TRACKING_PREPARE_H
#define TRACKING_PREPARE_H
#include "common.h"
#include "maxflow/graph.h"
#include <math.h>
#include <map>
#include <vector>
#include <thread>
#include <mutex>
class prepare {
typedef Graph<float,float,float> GraphType;
typedef struct {
int row;
int col;
int id;
int value;
}node;
typedef struct {
node first;
node second;
double weight;
}nLink;
typedef struct {
int id;
double weight;
}tLink;
public:
prepare(const cv::Mat _image, const cv::Mat _mask);
virtual ~prepare();
void update(const cv::Mat img);
private:
void generatePairs();
int getNodeId(int row, int col);
void computeBoundaryTerm();
void computeRegionBasedTerm();
int getRowFromId(int id);
int getColFromId(int id);
unsigned char getValueFromId(int id);
/**
* 使用多线程计算相邻像素值的方差
*/
double computeVariance();
GraphType *g;
cv::Mat image;
cv::Mat mask;
/**
* save node id pair between all neighbor points
*/
std::vector<std::pair<int, int> > pairs;
std::vector<node> nodes;
std::vector<nLink> nLinks;
std::vector<tLink> tLinks;
double lambda;
unsigned obj[256] = {0};
unsigned bkg[256] = {0};
cv::Mat distanceImage;
//直方图参数
int channels = 0;
cv::MatND objHist, bkgHist;
int dims = 1;
int size = 30;
float hranges[2] = {0, 180};
const float* ranges[1] = {hranges};
};
#endif //TRACKING_PREPARE_H