-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfun_test_10000p.m
207 lines (184 loc) · 7.6 KB
/
fun_test_10000p.m
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
%��ͶӰ���ͼÆ?��map������У�����ͽ������ѱ궨���궨
function fun_test(file);
%��ȡmap
%[A, Rm] = fun_para_readtxt();
%para=[Rm,A(1,1),A(1,3),A(2,2),A(2,3)];
%para = load('para_temp_25.txt');
para = load(file);
res_camera_w =1920;
res_camera_h = 1080;
n=20;
if 0
R=[];
for i=1:n %���������?¸ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿?
R_new=para([(i-1)*6+1 : (i-1)*6+6] );
% RL = vision.internal.calibration.rodriguesVectorToMatrix(R_new([1:3])');
Q1=R_new(1);
Q2=R_new(2);
Q3=R_new(3);
TL=R_new([4:6])';
RL=[cos(Q2)*cos(Q3) sin(Q1)*sin(Q2)*cos(Q3)-cos(Q1)*sin(Q3) cos(Q1)*sin(Q2)*cos(Q3)+sin(Q1)*sin(Q3); %��?ªï¿½ï¿½ï¿½ï¿½
cos(Q2)*sin(Q3) sin(Q1)*sin(Q2)*sin(Q3)+cos(Q1)*cos(Q3) cos(Q1)*sin(Q2)*sin(Q3)-sin(Q1)*cos(Q3);
-sin(Q2) sin(Q1)*cos(Q2) cos(Q1)*cos(Q2)];
RT=[RL(:,1:2) , TL];
R=[R;RT];
end
A=[para(n*6+1) 0 para(n*6+2); 0 para(n*6+3) para(n*6+4); 0,0,1];%�?½ï¿½ï¿½ï¿½?²ï¿½ï¿½ï¿?
%�?±ï¿½?¼?¼ï¿½ï¿½ï¿½ï¿½ï¿½?¤ï¿½ï¿½?¶??
value = imread('../image/speckle_pattern_4000_pad_0111_20_15000_2000.png');
value = value(200:1800,200:1800);
tic
for k=1:1:n
RT=R([(k-1)*3+1 : (k-1)*3+3],:);
result = fun_projection(value, A, RT, k);
imwrite(mat2gray(result), ['../image_twi/train_2_2/simulate_speckle_patent_proj_test_',num2str(k),'.png']);
end
roi = imread('../image/ROI_2000_2000_200.png');
roi = roi(200:1800,200:1800);
for k=1:1:n
RT=R([(k-1)*3+1 : (k-1)*3+3],:);
result = fun_projection(roi, A, RT, k);
imwrite(mat2gray(result), ['../image_twi/train_2_2/ROI_proj_test_',num2str(k),'.png']);
end
toc
%DIC����
pathname = '../image_twi/train_2_2/';
radius = 70; %DIC subset radius
spacing = 0;
% ��ï¿?ROI��pad�?±ä»¯ï¿½ï¿½ï¿½?µï¿½ï¿½ï¿½ncorr_auto_initseeds.m����ï¿?pad
parpool(20);
mat_name = ['../result/train_2_2_70_0080/speckle_map_test_'];
parfor k=1:1:n
tic
filename_ref = ['simulate_speckle_patent_proj_test_',num2str(k),'.png'];
filename_roi = ['ROI_proj_test_',num2str(k),'.png'];
filename_cur = ['cali_',num2str(k),'.png'];
displacements(k) = fun_dic(pathname, filename_ref, filename_roi ,filename_cur, radius, spacing, mat_name, k);
% save(['results/ori_ref_mat/speckle_map_',num2str(k),'.mat'],'displacements');
toc
end
delete(gcp('nocreate'));
end
if 0
mean_map_u = zeros(res_camera_h,res_camera_w);
mean_map_v = zeros(res_camera_h,res_camera_w);
plot_u = zeros(res_camera_h,res_camera_w,n);
plot_v = zeros(res_camera_h,res_camera_w,n);
for k = 1:1:n
str=strcat('../result/train_2_2_70_0080/speckle_map_test_',num2str(k),'.mat');
load(str);
plot_u(:,:,k) = displacements.plot_u;
plot_v(:,:,k) = displacements.plot_v;
plot_u_temp(:,:,k) = displacements.plot_u;
plot_v_temp(:,:,k) = displacements.plot_v;
end
for k = 1:1:n
for v_loc = 21:1:res_camera_h-20
for u_loc = 21:1:res_camera_w-20
temp_u_x = isequal(plot_u_temp(v_loc, u_loc, k),0) + isequal(plot_u_temp(v_loc, u_loc - 1, k),0) + isequal(plot_u_temp(v_loc, u_loc + 1, k),0);
temp_u_y = isequal(plot_u_temp(v_loc, u_loc, k),0) + isequal(plot_u_temp(v_loc - 1, u_loc, k),0) + isequal(plot_u_temp(v_loc + 1, u_loc, k),0);
temp_v_x = isequal(plot_v_temp(v_loc, u_loc, k),0) + isequal(plot_v_temp(v_loc, u_loc - 1, k),0) + isequal(plot_v_temp(v_loc, u_loc + 1, k),0);
temp_v_y = isequal(plot_v_temp(v_loc, u_loc, k),0) + isequal(plot_v_temp(v_loc - 1, u_loc, k),0) + isequal(plot_v_temp(v_loc + 1, u_loc, k),0);
if temp_u_x > 0 && temp_u_x < 3 || temp_u_y > 0 && temp_u_y < 3 || temp_v_x > 0 && temp_v_x < 3 || temp_v_y > 0 && temp_v_y < 3
plot_u(v_loc-20:v_loc+20, u_loc-20:u_loc+20, k) = 0;
plot_v(v_loc-20:v_loc+20, u_loc-20:u_loc+20, k) = 0;
end
end
end
end
count_sum = 0;
for v_loc = 1:1:res_camera_h
for u_loc = 1:1:res_camera_w
count = 0;
bias_sum_u = 0;
bias_sum_v = 0;
for k = 1:1:n
u_bias = plot_u(v_loc,u_loc,k);
v_bias = plot_v(v_loc,u_loc,k);
if u_bias~=0 || v_bias~=0
count = count+1;
bias_sum_u = bias_sum_u + u_bias;
bias_sum_v = bias_sum_v + v_bias;
end
end
if count~=0
mean_map_u(v_loc,u_loc) = bias_sum_u/count;
mean_map_v(v_loc,u_loc) = bias_sum_v/count;
end
count_sum = count_sum + count;
end
end
save(['../result/train_2_2_70_0080/speckle_map_test_70.mat'],'mean_map_u','mean_map_v');
plot_u = zeros(res_camera_h,res_camera_w);
plot_v = zeros(res_camera_h,res_camera_w);
%pathname = 'image/ori_0315/';
%imshow(mean_map_u);
end
if 0
fid = fopen('/home/wsco/cnn/calibration/camera_calibration_distance_calculate/build/applications/camera_calibration/points_correct.txt','w');
points=load('/home/wsco/cnn/calibration/camera_calibration_distance_calculate/build/applications/camera_calibration/points_with_index.txt');
load('../result/train_2_1/speckle_map_test_2.mat');
mean_map_u_1 = mean_map_u;
mean_map_v_1 = mean_map_v;
load('../result/train_2_2_70/speckle_map_test_70.mat');
mean_map_u_2 = mean_map_u;
mean_map_v_2 = mean_map_v;
for k=1:1:36030
u_bias = mean_map_u(i,j);
v_bias = mean_map_v(i,j);
if u_bias == 0 || v_bias == 0 || j + u_bias < 1 || i + v_bias < 1 || j + u_bias > 1920 || i + v_bias > 1080
I_correct(i,j) = I(i,j);
else
uu = j + u_bias;
vv = i + v_bias;
%˫���Բ�ֵ
value_1 = I(floor(vv),floor(uu));
value_2 = I(floor(vv),ceil(uu));
value_3 = I(ceil(vv),ceil(uu));
value_4 = I(ceil(vv),floor(uu));
result_1 = (ceil(vv) - vv) * value_1 + (vv - floor(vv)) * value_4;
result_2 = (ceil(vv) - vv) * value_2 + (vv - floor(vv)) * value_3;
result_value = (ceil(uu) - uu) * result_1 + (uu - floor(uu)) * result_2;
I_correct(i,j) = result_value;
end
% imshow(I_correct/max(I_correct(:)));
imwrite(I_correct/max(I_correct(:)), ['../image_twi/train_2_2/correct_',num2str(k),'.png']);
end
end
if 0
%��ȡ���Ƶ�
height_ref = 1000;
width_ref = 1000;
pad = 100;
pathname = '../image_twi/';
filename_ref = 'speckle_pattern_4000_pad_0111_20_15000_1000.png';
filename_roi = 'ROI_1000_1000_100.png';
radius = 70; %DIC subset radius
spacing = 0;
% ���ROI��pad�б仯���ǵ���ncorr_auto_initseeds.m�����pad
parpool(20);
mat_name = ['../result/train_2_2_70_0080/speckle_correct_'];
parfor k=1:1:n
tic
filename_cur = ['train_2_2/correct_',num2str(k),'.png'];
displacements = fun_dic(pathname, filename_ref, filename_roi ,filename_cur, radius, spacing, mat_name, k);
% save(['results/ori_ref_mat/speckle_correct_',num2str(k),'.mat'],'displacements');
toc
delete(gcp('nocreate'));
end
if 1
for k = 1:1:n
load(str);
for v_loc = 200:100:800
for u_loc = 200:100:800
% 19.2 = (1728-2*96)/(140+1)��ȥ���߿����Ƶ��ļ��
u_bias = displacements.plot_u(v_loc,u_loc);
v_bias = displacements.plot_v(v_loc,u_loc);
uu = u_loc + u_bias;
vv = v_loc + v_bias;
fprintf(fid, '%f %f\n',uu,vv);
end
end
end
fclose(fid);
end