-
Notifications
You must be signed in to change notification settings - Fork 14
/
SGMStereo.h
98 lines (86 loc) · 3.69 KB
/
SGMStereo.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
/*
Copyright (C) 2014 Koichiro Yamaguchi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <opencv2/opencv.hpp>
class SGMStereo {
public:
SGMStereo();
void setDisparityTotal(const int disparityTotal);
void setDisparityFactor(const double disparityFactor);
void setDataCostParameters(const int sobelCapValue,
const int censusWindowRadius,
const double censusWeightFactor,
const int aggregationWindowRadius);
void setSmoothnessCostParameters(const int smoothnessPenaltySmall, const int smoothnessPenaltyLarge);
void setConsistencyThreshold(const int consistencyThreshold);
void compute(const cv::Mat& leftImage,
const cv::Mat& rightImage,
float* disparityImage);
private:
void initialize(const cv::Mat& leftImage, const cv::Mat& rightImage);
void setImageSize(const cv::Mat& leftImage, const cv::Mat& rightImage);
void allocateDataBuffer();
void freeDataBuffer();
void computeCostImage(const cv::Mat& leftImage, const cv::Mat& rightImage);
void convertToGrayscale(const cv::Mat& leftImage,
const cv::Mat& rightImage,
unsigned char* leftGrayscaleImage,
unsigned char* rightGrayscaleImage) const;
void computeLeftCostImage(const unsigned char* leftGrayscaleImage, const unsigned char* rightGrayscaleImage);
void computeCappedSobelImage(const unsigned char* image, const bool horizontalFlip, unsigned char* sobelImage) const;
void computeCensusImage(const unsigned char* image, int* censusImage) const;
void calcTopRowCost(unsigned char*& leftSobelRow, int*& leftCensusRow,
unsigned char*& rightSobelRow, int*& rightCensusRow,
unsigned short* costImageRow);
void calcRowCosts(unsigned char*& leftSobelRow, int*& leftCensusRow,
unsigned char*& rightSobelRow, int*& rightCensusRow,
unsigned short* costImageRow);
void calcPixelwiseSAD(const unsigned char* leftSobelRow, const unsigned char* rightSobelRow);
void calcHalfPixelRight(const unsigned char* rightSobelRow);
void addPixelwiseHamming(const int* leftCensusRow, const int* rightCensusRow);
void computeRightCostImage();
void performSGM(unsigned short* costImage, unsigned short* disparityImage);
void speckleFilter(const int maxSpeckleSize, const int maxDifference, unsigned short* image) const;
void enforceLeftRightConsistency(unsigned short* leftDisparityImage, unsigned short* rightDisparityImage) const;
// Parameter
int disparityTotal_;
double disparityFactor_;
int sobelCapValue_;
int censusWindowRadius_;
double censusWeightFactor_;
int aggregationWindowRadius_;
int smoothnessPenaltySmall_;
int smoothnessPenaltyLarge_;
int consistencyThreshold_;
// Data
int width_;
int height_;
int widthStep_;
unsigned short* leftCostImage_;
unsigned short* rightCostImage_;
unsigned char* pixelwiseCostRow_;
unsigned short* rowAggregatedCost_;
unsigned char* halfPixelRightMin_;
unsigned char* halfPixelRightMax_;
int pathRowBufferTotal_;
int disparitySize_;
int pathTotal_;
int pathDisparitySize_;
int costSumBufferRowSize_;
int costSumBufferSize_;
int pathMinCostBufferSize_;
int pathCostBufferSize_;
int totalBufferSize_;
short* sgmBuffer_;
};