-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.cpp
96 lines (62 loc) · 3.07 KB
/
main.cpp
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
//******************************************************************************
/*
DepthComp : efficient depth filling appraoch built on segmentation
Requirements: depth image / segmented image
Usage: ./depthComp <path_to_depth_image> <path_to_segmented_image>
Implementation of DepthComp - Atapour-Abarghouei / Breckon, Proc. BMVC 2017.
Author : Amir Atapour-Abarghouei, [email protected]
Copyright (c) 2017 Engineering and Computing Sciences, Durham University
License : GPL - http://www.gnu.org/licenses/gpl.html
*/
//******************************************************************************
#include "depthComp.hpp"
using namespace cv;
using namespace std;
// *****************************************************************************
void writeOutputImg(const String& imgName, const String& sufix, const Mat& mat)
{
assert(!mat.empty());
string delimiter = ".png";
string token = imgName.substr(0, imgName.find(delimiter));
string outFileName = token + sufix + delimiter;
imwrite(outFileName, mat);
}
// *****************************************************************************
int main( int argc, char** argv ){
Mat depthIn; // input depth image (with holes)
Mat labelIn, labelRszd; // input segmented label image
Mat depthOut ; // output depth image (completed)
// check arguments and read in images
if(argc == 3) {
if ((depthIn = imread(argv[1], IMREAD_GRAYSCALE)).empty()) {
cout << "\nCannot open file " << argv[1] << endl;
exit(-1);
}
if ((labelIn = imread(argv[2], IMREAD_COLOR)).empty()) {
cout << "\nCannot open file " << argv[2] << endl;
exit(-1);
}
} else {
cout << "Usage: ./depthComp <depth_image> <segmented_image>" << endl;
exit(-1);
}
// resize label image to depth image size (just in case different)
resize(labelIn, labelRszd, depthIn.size());
// normalize (stretch) labels and convert to grayscale to ensure unqiue
// mapping (for low numbers of labels, i.e. < 255)
normalize(labelRszd, labelRszd, 0, 255, NORM_MINMAX);
cvtColor(labelRszd, labelRszd, COLOR_BGR2GRAY);
// define depth completion object
DepthComp completer;
// perform pre-processing and write output to file
depthIn = completer.preProcess(depthIn, labelRszd, true);
writeOutputImg(argv[1], "-PROCESSED", depthIn);
// perform depthComp based depth completion
// recording stats of the process out to data.txt
depthOut = completer.identFillHoles(depthIn, labelRszd, true);
depthOut = completer.postProcess(depthOut, labelRszd, true);
// write filled depth image to file
writeOutputImg(argv[1], "-FILLED", depthOut);
return 0; // end of program
}// end of main
//******************************************************************************