-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_backPano.cpp
More file actions
164 lines (142 loc) · 5.56 KB
/
debug_backPano.cpp
File metadata and controls
164 lines (142 loc) · 5.56 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// Created by ale on 19-3-19.
//
#include <vector>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
//pano_image_f.size() == pano_depth_f.size()
void GenerateBackPano(cv::Mat& pano_image_f, cv::Mat& pano_depth_f, cv::Mat& pano_image_b, cv::Mat& pano_depth_b, const int icount = 30)//iterator count)
{
//init
cv::Mat image_f(pano_image_f.size()+Size(icount*2, icount*2), CV_8UC3, Scalar(0,0,0));
cv::Mat image_b(pano_image_f.size()+Size(icount*2, icount*2), CV_8UC3, Scalar(0,0,0));
cv::Mat depth_f(pano_depth_f.size()+Size(icount*2, icount*2), CV_32FC1, Scalar(0.0f));
cv::Mat depth_b(pano_depth_f.size()+Size(icount*2, icount*2), CV_32FC1, Scalar(0.0f));
//image_f(Rect(icount, icount, pano_image_f.cols, pano_image_f.rows)) = pano_image_f.clone();
//depth_f(Rect(icount, icount, pano_depth_f.cols, pano_depth_f.rows)) = pano_depth_f.clone();
Mat roi= image_f(Rect(icount, icount, pano_image_f.cols, pano_image_f.rows));
pano_image_f.copyTo(roi);
roi = depth_f(Rect(icount, icount, pano_depth_f.cols, pano_depth_f.rows));
pano_depth_f.copyTo(roi);
//imshow("pano_image_f", pano_image_f);
//imshow("pano_depth_f", pano_depth_f);
imshow("image_f", image_f);
imshow("depth_f", depth_f);
//waitKey();
float d, dl, dr, dt, db;//current depth, left-right-top-bottom depth.
float diff = 0.05;
for(int h=0; h<pano_depth_f.rows; ++h)
{
for(int w=0; w<pano_depth_f.cols; ++w)
{
//只处理有深度值的邻域,否则跳过
d = depth_f.at<float>(h+icount, w+icount);
if(!(d > 1e-6f))
continue;
dl = depth_f.at<float>(h+icount, w-1+icount);
dr = depth_f.at<float>(h+icount, w+1+icount);
dt = depth_f.at<float>(h-1+icount, w+icount);
db = depth_f.at<float>(h+1+icount, w+icount);
//left
if(dl-d>diff*d || !(dl > 1e-6f))
depth_b.at<float>(h+icount, w-1+icount) = d;
//right
if(dr-d>diff*d || !(dr > 1e-6f))
depth_b.at<float>(h+icount, w+1+icount) = d;
//top
if(dt-d>diff*d || !(dt > 1e-6f))
depth_b.at<float>((h-1+icount, w+icount)) = d;
//bottom
if(db-d>diff*d || !(db > 1e-6f))
depth_b.at<float>((h+1+icount, w+icount)) = d;
}
}
cout<<"begin iterate"<<endl;
//iterate icount-1
for(int k = 0; k<icount-1; ++k)
{
cv::Mat depth_b_t = depth_b.clone();
for(int h=1; h<depth_b.rows-1; ++h)
{
for(int w=1; w<depth_b.cols-1; ++w)
{
//只处理有深度值的邻域,否则跳过
d = depth_b.at<float>(h, w);
if(!(d > 1e-6f))
continue;
dl = depth_b.at<float>(h, w-1);
dr = depth_b.at<float>(h, w+1);
dt = depth_b.at<float>(h-1, w);
db = depth_b.at<float>(h+1, w);
float dl_f = depth_f.at<float>(h, w-1);
float dr_f = depth_f.at<float>(h, w+1);
float dt_f = depth_f.at<float>(h-1, w);
float db_f = depth_f.at<float>(h+1, w);
//left
if(!(dl > 1e-6f) || dl>d )//&& d <= depth_f.at<float>(h, w-1))
if(dl_f>1e-6f&&dl_f>d || !(dl_f>1e-6f))
depth_b_t.at<float>(h, w-1) = d;
//right
if(!(dr > 1e-6f) || dr>d )//&& d <= depth_f.at<float>(h, w+1))
if(dr_f>1e-6f&&dr_f>d || !(dr_f>1e-6f))
depth_b_t.at<float>(h, w+1) = d;
//top
if(!(dt > 1e-6f) || dt>d)//&& d <= depth_f.at<float>(h-1, w))
if(dt_f>1e-6f&&dt_f>d || !(dt_f>1e-6f))
depth_b_t.at<float>(h-1, w) = d;
//bottom
if(!(db > 1e-6f) || db>d)//&& d <= depth_f.at<float>(h+1, w))
if(db_f>1e-6f&&db_f>d || !(db_f>1e-6f))
depth_b_t.at<float>(h+1, w) = d;
}
}
depth_b = depth_b_t;
}
//prune
for(int h=0; h<depth_b.rows; ++h)
{
for(int w=0; w<depth_b.cols; ++w)
{
//只处理有深度值的邻域,否则跳过
d = depth_b.at<float>(h, w);
if(!(d > 1e-6f))
continue;
float df = depth_f.at<float>(h, w);
if(df>1e-6f && df<d)
depth_b.at<float>(h, w) = 0.0f;
}
}
cv::Mat prune = depth_f>depth_b;
cv::Mat temp_depth_b;
depth_b.copyTo(temp_depth_b, prune);
imshow("temp_depth_b", temp_depth_b);
//inpainting
cout<<"begin inpainting"<<endl;
cv::Mat mask = depth_b>0;
cout<<sum(mask)<<endl;
inpaint(image_f, mask, image_b, 5, CV_INPAINT_NS);
imshow("image_b", image_b);
imshow("depth_b", depth_b);
waitKey();
//color inpainting
}
//main()函数
int main(int argc, char** argv)
{
//载入原图
cv::Mat pano_image_f = imread("pano_result.jpg", 1);
cv::Mat pano_depth_f = imread("pano_result.png", CV_LOAD_IMAGE_ANYCOLOR|CV_LOAD_IMAGE_ANYDEPTH);
if (!pano_image_f.data || !pano_depth_f.data)
{
printf("读取g_srcImage错误!\n");
return false;
}
pano_depth_f.convertTo(pano_depth_f, CV_32FC1);
double minVal, maxVal;
minMaxLoc(pano_depth_f, &minVal, &maxVal);
cout<<minVal<<", "<<maxVal<<endl;
cv::Mat pano_image_b, pano_depth_b;
GenerateBackPano(pano_image_f, pano_depth_f, pano_image_b, pano_depth_b);
return 0;
}