Skip to content

Commit f7491c7

Browse files
committed
update
1 parent 3e3b13b commit f7491c7

File tree

111 files changed

+4696
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4696
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
import glob
2+
from default_params import default_params
3+
import skimage.io
4+
import numpy as np
5+
from PIL import Image, ImageDraw
6+
import matplotlib.pyplot as plt
7+
import os.path
8+
import skimage.io
9+
import time
10+
import json
11+
import multiprocessing
12+
13+
import skimage.io
14+
from Panos.Pano_rectification import simon_rectification
15+
from Panos.Pano_project import project_face, stitch_tiles, render_imgs
16+
import matplotlib.pyplot as plt
17+
18+
from Panos.Pano_visualization import R_heading, draw_all_vp_and_hl_color, draw_all_vp_and_hl_bi, \
19+
draw_zenith_on_top_color, draw_zenith_on_top_bi, draw_sphere_zenith, R_roll, R_pitch
20+
from Panos.Pano_zp_hvp import calculate_consensus_zp
21+
from Panos.Pano_consensus_vis import draw_consensus_zp_hvps, draw_consensus_rectified_sphere, \
22+
draw_center_hvps_rectified_sphere, draw_center_hvps_on_panorams
23+
import Pano_hvp
24+
from Panos.Pano_histogram import calculate_histogram
25+
from Panos.Pano_project import project_facade_for_refine
26+
27+
########## add new random seed
28+
#np.random.seed(1)
29+
30+
plot_redundant = False
31+
save_directly = True
32+
33+
root = 'Pano_new'
34+
35+
Country_city = 'New'
36+
37+
new_count = 5
38+
39+
tmp_count = str(new_count)
40+
41+
42+
43+
Img_folder = os.path.join(root, Country_city, 'images/')
44+
inter_Dir = os.path.join(root, 'Pano_hl_z_vp/')
45+
46+
47+
48+
imageList = glob.glob(Img_folder + '*.jpg')
49+
imageList.sort()
50+
51+
rendering_output_folder = os.path.join(root, Country_city, 'Rendering')
52+
if not os.path.exists(rendering_output_folder):
53+
os.makedirs(rendering_output_folder)
54+
55+
56+
#for im_path in ['/home/zhup/Desktop/GSV_Pano_val/Val/images/9wG3a9VOkwTSqnq6zsbdSQ.jpg']:
57+
# for im_path in imageList[10*new_count:10*(new_count+1)]:
58+
for im_path in imageList:
59+
print(im_path)
60+
im = Image.open(im_path)
61+
# rendering_img_base = os.path.join(rendering_output_folder, os.path.splitext(os.path.basename(im_path))[0])
62+
rendering_img_base = os.path.join(rendering_output_folder, os.path.splitext(os.path.basename(im_path))[0])
63+
64+
task = 'hahaha/'
65+
thread_num = 1
66+
thread = str(thread_num) + '/'
67+
tmp_folder = os.path.join(root, Country_city, 'tmp', task, thread)
68+
69+
if not os.path.exists(tmp_folder):
70+
os.makedirs(tmp_folder)
71+
removelist = glob.glob(tmp_folder + '*.jpg')
72+
for i in removelist:
73+
os.remove(i)
74+
75+
#render_num = 16
76+
render_num = 4
77+
start = int(-render_num / 2) + 1
78+
end = render_num + start
79+
degree = 360 / render_num
80+
panorama_img = skimage.io.imread(im_path)
81+
coordinates_list = []
82+
83+
84+
tilelist = render_imgs(panorama_img, tmp_folder, save_directly)
85+
if not save_directly:
86+
tilelist = glob.glob(tmp_folder + '*.jpg')
87+
tilelist.sort()
88+
89+
hl = []
90+
hvps = []
91+
hvp_groups = []
92+
z = []
93+
z_group = []
94+
ls = []
95+
z_homo = []
96+
hvp_homo = []
97+
ls_homo = []
98+
99+
for i in range(len(tilelist)):
100+
[tmp_hl, tmp_hvps, tmp_hvp_groups, tmp_z, tmp_z_group, tmp_ls, tmp_z_homo, tmp_hvp_homo, tmp_ls_homo, params] = simon_rectification(tilelist[i], i, inter_Dir, root, tmp_count)
101+
hl.append(tmp_hl)
102+
hvps.append(tmp_hvps)
103+
hvp_groups.append(tmp_hvp_groups)
104+
z.append(tmp_z)
105+
z_group.append(tmp_z_group)
106+
ls.append(tmp_ls)
107+
z_homo.append(tmp_z_homo)
108+
hvp_homo.append(tmp_hvp_homo)
109+
ls_homo.append(tmp_ls_homo)
110+
111+
# print('get all the zenith points')
112+
113+
114+
removelist = glob.glob(tmp_folder + '*.jpg')
115+
for i in removelist:
116+
os.remove(i)
117+
118+
####################### Get all the zenith points from all the (8) viewpoints
119+
120+
zenith_points = np.array([R_heading(np.pi / 2 * (i - 1)).dot(zenith) for i, zenith in enumerate(z_homo)])
121+
points2 = np.array([R_heading(np.pi / 2 * (i - 1)).dot(np.array([0., 0., 1.])) for i in range(len(z_homo))])
122+
hv_points = [(R_heading(np.pi / 2 * (i - 1)).dot(hv_p.T)).T for i, hv_p in enumerate(hvp_homo)]
123+
124+
125+
if plot_redundant:
126+
draw_all_vp_and_hl_color(zenith_points, hv_points, im.copy(), root)
127+
128+
draw_all_vp_and_hl_bi(zenith_points, hv_points, im.copy(), root)
129+
#draw_zenith_on_top_color(zenith_points, root)
130+
#draw_zenith_on_top_bi(zenith_points, root)
131+
draw_sphere_zenith(zenith_points, hv_points, root)
132+
133+
134+
135+
####################### Calculate the consensus zenith point
136+
137+
[zenith_consensus, best_zenith] = calculate_consensus_zp(zenith_points, method='svd')
138+
139+
# Transform the zenith points back to original homogeneous coordinates
140+
# zenith_consensus_org = np.array(
141+
# [R_heading(-np.pi / 6 * (i - 5)).dot(zenith) for i, zenith in enumerate(zenith_consensus)])
142+
zenith_consensus_org = np.array([R_heading(-np.pi / 2 * (i - 1)).dot(zenith) for i, zenith in enumerate(zenith_consensus)])
143+
144+
145+
146+
result_list = []
147+
for i in range(len(zenith_consensus_org)):
148+
149+
#result = Pano_hvp.hvp_from_zenith(ls_homo[i], zenith_consensus_org[i], params)
150+
151+
result = Pano_hvp.get_all_hvps(ls_homo[i], zenith_consensus_org[i], params)
152+
result_list.append(result)
153+
154+
hvps_consensus_org = []
155+
for i in range(len(result_list)):
156+
# hvps_consensus_org.append(result_list[i]['hvp_homo'])
157+
hvps_consensus_org.append(result_list[i])
158+
159+
hvps_consensus_uni = [(R_heading(np.pi / 2 * (i - 1)).dot(hv_p.T)).T for i, hv_p in enumerate(hvps_consensus_org)]
160+
161+
if plot_redundant:
162+
draw_consensus_zp_hvps(best_zenith, hvps_consensus_uni, im.copy(), root)
163+
164+
165+
####################### Calculate pitch and roll
166+
pitch = np.arctan(best_zenith[2] / best_zenith[1])
167+
roll = - np.arctan(best_zenith[0] / np.sign(best_zenith[1]) * np.hypot(best_zenith[1], best_zenith[2]))
168+
169+
170+
hvps_consensus_rectified = [R_roll(-roll).dot(R_pitch(-pitch).dot(vp.T)).T for vp in hvps_consensus_uni]
171+
172+
if plot_redundant:
173+
draw_consensus_rectified_sphere(hvps_consensus_rectified, root)
174+
175+
176+
177+
###################### Calculate horizontal VP histogram
178+
179+
final_hvps_rectified = calculate_histogram(hvps_consensus_rectified, root, plot_redundant)
180+
181+
# final_hvps_rectified = [np.array([1.,0.,0.]), np.array([0.,0.,1.])]
182+
# pitch = 0
183+
# roll = 0
184+
185+
186+
# rrd = np.random.rand() * np.pi
187+
# final_hvps_rectified = [np.array([np.sin(rrd), 0., np.cos(rrd)]), np.array([np.sin(np.pi/2 + rrd), 0., np.cos(np.pi/2 + rrd)])]
188+
# pitch = 0
189+
# roll = 0
190+
191+
192+
193+
194+
# Test whether the main vanishing point is near 90 degrees to the second vanishing point
195+
196+
# if len(final_hvps_rectified) == 2:
197+
# hvp1 = final_hvps_rectified[0]
198+
# hvp2 = final_hvps_rectified[1]
199+
# if np.abs(hvp1.dot(hvp2)) > np.sin(np.radians(5)):
200+
# final_hvps_rectified = [final_hvps_rectified[0]]
201+
202+
if plot_redundant:
203+
draw_center_hvps_rectified_sphere(np.array(final_hvps_rectified), root)
204+
draw_center_hvps_on_panorams(best_zenith, np.array(final_hvps_rectified), im.copy(), pitch, roll, root)
205+
206+
207+
208+
# Draw rectified panorama
209+
210+
# from Panos.Pano_new_pano import create_new_panorama, draw_new_panorama
211+
# if plot_redundant:
212+
# new_pano_path = create_new_panorama(im_path, pitch, roll, root)
213+
# draw_new_panorama(new_pano_path, np.array(final_hvps_rectified), root)
214+
215+
216+
217+
###################### Rendering images from panoramas
218+
219+
project_facade_for_refine(np.array(final_hvps_rectified), im.copy(), pitch, roll, im_path, root, tmp_folder, rendering_img_base, tmp_count)
220+
print(100)
221+
222+

0 commit comments

Comments
 (0)