This repository has been archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SGM.h
135 lines (117 loc) · 3.88 KB
/
SGM.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _SGM_H_
#define _SGM_H_
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <limits>
#include <iostream>
#define DISP_RANGE 130
#define DIS_FACTOR 1
#define CENSUS_W 5
#define DISFLAG 255
#define Disthreshold 10000
#define Outlier 255
#define Vmax 0.3f
#define disparityThreshold 2
#define Dinvd 0
using namespace cv;
class SGM
{
protected:
typedef Vec<float, DISP_RANGE> VecDf;
int PENALTY1;
int PENALTY2;
const int winRadius;
const cv::Mat &imgLeft;
const cv::Mat &imgRight;
const cv::Mat &imgLeftLast;
cv::Mat censusImageRight;
cv::Mat censusImageLeft;
cv::Mat censusImageLeftLast;
cv::Mat cost;
cv::Mat directCost;
cv::Mat accumulatedCost;
int HEIGHT;
int WIDTH;
void computeCensus(const cv::Mat &image, cv::Mat &censusImg);
int computeHammingDist(const uchar left, const uchar right);
VecDf addPenalty(VecDf const& prior, VecDf &local, float path_intensity_gradient);
void sumOverAllCost();
virtual void createDisparity(cv::Mat &disparity);
template <int DIRX, int DIRY> void aggregation(cv::Mat cost);
virtual void computeDerivative();
virtual void computeCost();
virtual void postProcess(cv::Mat &disparityIn,cv::Mat &disparity);
public:
SGM(const cv::Mat &imgLeftLast_, const cv::Mat &imgLeft_, const cv::Mat &imgRight_, const int PENALTY1_, const int PENALTY2_, const int winRadius_);
void setPenalty(const int penalty_1, const int penalty_2);
void runSGM(cv::Mat &disparity);
virtual void writeDerivative();
virtual ~SGM();
};
class SGMStereo : public SGM
{
protected:
cv::Mat derivativeStereoLeft;
cv::Mat derivativeStereoRight;
virtual void computeDerivative();
virtual void computeCost();
virtual void postProcess(cv::Mat &disparityIn,cv::Mat &disparity);
public:
SGMStereo(const cv::Mat &imgLeftLast_, const cv::Mat &imgLeft_, const cv::Mat &imgRight_, const int PENALTY1_, const int PENALTY2_, const int winRadius_);
virtual ~SGMStereo();
virtual void writeDerivative();
};
class SGMFlow : public SGM
{
protected:
cv::Mat imgRotation;
cv::Mat EpipoleLeftLast;
cv::Mat EpipoleLeft;
cv::Mat translationLeftLast;
cv::Mat translationLeft;
cv::Mat fundamentalMatrix;
cv::Mat derivativeFlowLeftLast;
cv::Mat derivativeFlowLeft;
cv::Mat disFlag;
virtual void computeDerivative();
virtual void computeCost();
virtual void postProcess(cv::Mat &disparityIn,cv::Mat &disparity);
void computeRotation();
void computeTranslation(cv::Mat &translation, cv::Mat &Epipole);
public:
SGMFlow(const cv::Mat &imgLeftLast_, const cv::Mat &imgLeft_, const cv::Mat &imgRight_, const int PENALTY1_, const int PENALTY2_, const int winRadius_,
cv::Mat &EpipoleLeftLast_, cv::Mat &EpipoleLeft_, cv::Mat &fundamentalMatrix_);
virtual ~SGMFlow();
virtual void writeDerivative();
void copyDisflag(cv::Mat &M);
};
class SGMStereoFlow : public SGM
{
protected:
cv::Mat imgRotation;
cv::Mat EpipoleLeftLast;
cv::Mat EpipoleLeft;
cv::Mat translationLeftLast;
cv::Mat translationLeft;
cv::Mat fundamentalMatrix;
cv::Mat derivativeStereoLeft;
cv::Mat derivativeStereoRight;
cv::Mat derivativeFlowLeftLast;
cv::Mat derivativeFlowLeft;
cv::Mat disFlag;
cv::Mat eviStereo;
cv::Mat eviFlow;
cv::Vec3f ransacAlpha;
virtual void computeCost();
virtual void computeDerivative();
void computeRotation();
void computeTranslation(cv::Mat &translation, cv::Mat &Epipole);
virtual void postProcess(cv::Mat &disparityIn,cv::Mat &disparity);
public:
SGMStereoFlow(const cv::Mat &imgLeftLast_, const cv::Mat &imgLeft_,const cv::Mat &imgRight_, const int PENALTY1_, const int PENALTY2_, const int winRadius_,
cv::Mat &EpipoleLeftLast_, cv::Mat &EpipoleLeft_, cv::Mat &fundamentalMatrix_);
void setAlphaRansac(cv::Mat &disparity, cv::Mat &disparityFlow, cv::Mat &disflag_);
void setEvidence(cv::Mat &eviStereo_, cv::Mat &eviFlow_ ,cv::Mat &disflag_);
virtual ~SGMStereoFlow();
};
#endif