Upload streamlit_app.py
Browse files- streamlit_app.py +438 -0
streamlit_app.py
ADDED
@@ -0,0 +1,438 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import moduls.Texture as texture
|
3 |
+
from PIL import Image
|
4 |
+
import mmcv
|
5 |
+
import moduls.model
|
6 |
+
from moduls.texture_for_point import texture_transformation_1
|
7 |
+
from main import model
|
8 |
+
import numpy as np
|
9 |
+
import cv2
|
10 |
+
import os
|
11 |
+
from streamlit_image_select import image_select
|
12 |
+
from streamlit_image_annotation import pointdet
|
13 |
+
from moduls.conturs import conturs_on_image
|
14 |
+
from streamlit_image_comparison import image_comparison
|
15 |
+
from moduls.settings import path_for_streamlit
|
16 |
+
st.set_page_config(layout="wide")
|
17 |
+
|
18 |
+
|
19 |
+
@st.cache_data
|
20 |
+
def load_image(image_file):
|
21 |
+
img = Image.open(image_file)
|
22 |
+
img = mmcv.imread(np.array(img))
|
23 |
+
return img
|
24 |
+
def save_file_st(path_file):
|
25 |
+
file_name = path_file.name
|
26 |
+
img = load_image(path_file)
|
27 |
+
im = Image.fromarray(img)
|
28 |
+
output_filename = 'processing.jpg'
|
29 |
+
im.save(output_filename)
|
30 |
+
return output_filename
|
31 |
+
@st.dialog("Выбор текстуры пола", width = 'large')
|
32 |
+
def select_floor(img_list_1, image_1, img_list):
|
33 |
+
tex_floor = image_select("Выбор текстуры пола", img_list_1, return_value= 'index')
|
34 |
+
if st.button("Выбрать"):
|
35 |
+
st.session_state.json_list[0] = img_list[tex_floor]
|
36 |
+
modificate_image('floor')
|
37 |
+
st.session_state.select_floor = [tex_floor]
|
38 |
+
st.rerun()
|
39 |
+
@st.dialog("Выбор текстуры стен", width = 'large')
|
40 |
+
def select_wall(img_list_1, image_1, img_list):
|
41 |
+
tex_wall = image_select("Выбор текстуры стен", img_list_1, return_value= 'index')
|
42 |
+
if st.button("Выбрать"):
|
43 |
+
st.session_state.json_list[1] = img_list[tex_wall]
|
44 |
+
modificate_image('wall')
|
45 |
+
st.session_state.select_wall = [tex_wall]
|
46 |
+
st.rerun()
|
47 |
+
@st.dialog("Выбор текстуры потолка", width = 'large')
|
48 |
+
def select_ceiling(img_list_1, image_1, img_list):
|
49 |
+
tex_ceiling = image_select("Выбор текстуры потолка", img_list_1, return_value= 'index')
|
50 |
+
if st.button("Выбрать"):
|
51 |
+
st.session_state.json_list[2] = img_list[tex_ceiling]
|
52 |
+
modificate_image('ceiling')
|
53 |
+
st.session_state.select_ceiling = [tex_ceiling]
|
54 |
+
st.rerun()
|
55 |
+
def points_sorter(points):
|
56 |
+
messages_list = ['Недостаточно точек. Добавьте точек!',
|
57 |
+
'Точек не четное количество. Добавьте или уберите точку!',
|
58 |
+
'Точек слишком много. Уберите лишние точки!',
|
59 |
+
'Точки успешно отсортированы!',
|
60 |
+
'Пол или потолок имеют обратную перспективу. Скорректируйте точки!']
|
61 |
+
print('len(points)', len(points))
|
62 |
+
print(points)
|
63 |
+
if (num_points := len(points)) < 6:
|
64 |
+
return [], []
|
65 |
+
elif num_points%2 != 0:
|
66 |
+
return [], []
|
67 |
+
elif num_points > 8:
|
68 |
+
return [], []
|
69 |
+
else:
|
70 |
+
# Сортируем список по y, а при равных y по х
|
71 |
+
sorted_list = sorted(points, key=lambda k: [k[1], k[0]])
|
72 |
+
print('sorted_list', sorted_list)
|
73 |
+
# Делим список пополам и сортируем по x
|
74 |
+
ceiling_points = sorted(sorted_list[:num_points//2], key=lambda k: [k[0], k[1]])
|
75 |
+
floor_points = sorted(sorted_list[num_points//2:], key=lambda k: [k[0], k[1]])
|
76 |
+
bad_points = []
|
77 |
+
print('ceiling_points, floor_points', ceiling_points, floor_points)
|
78 |
+
# Проверяем направление перспективы потолка
|
79 |
+
if ceiling_points[0][1] > ceiling_points[1][1]:
|
80 |
+
bad_points.append(ceiling_points[0])
|
81 |
+
bad_points.append(ceiling_points[1])
|
82 |
+
if ceiling_points[-1][1] > ceiling_points[-2][1]:
|
83 |
+
bad_points.append(ceiling_points[-1])
|
84 |
+
bad_points.append(ceiling_points[-2])
|
85 |
+
# Проверем направление перспективы пола
|
86 |
+
if floor_points[0][1] < floor_points[1][1]:
|
87 |
+
bad_points.append(floor_points[0])
|
88 |
+
bad_points.append(floor_points[1])
|
89 |
+
if floor_points[-1][1] < floor_points[-2][1]:
|
90 |
+
bad_points.append(floor_points[-1])
|
91 |
+
bad_points.append(floor_points[-2])
|
92 |
+
c_f_point = [ceiling_points, floor_points]
|
93 |
+
return c_f_point
|
94 |
+
#if len(bad_points) != 0:
|
95 |
+
# return ceiling_points, floor_points
|
96 |
+
#else:
|
97 |
+
# return ceiling_points, floor_points
|
98 |
+
#@st.dialog('Определение углов комнаты', width='large')
|
99 |
+
def corner_change_2(image_path):
|
100 |
+
list_1 = ['Угол']
|
101 |
+
list_label_1 = []
|
102 |
+
list_label_2 = []
|
103 |
+
list_point_1 = []
|
104 |
+
list_point_2 = []
|
105 |
+
if 'ceiling_point' in st.session_state and 'floor_point' in st.session_state and st.session_state.ceiling_point is not None and st.session_state.floor_point is not None:
|
106 |
+
list_point_1 = st.session_state.ceiling_point
|
107 |
+
print('list_point_1', list_point_1)
|
108 |
+
for i in range(len(st.session_state.ceiling_point)):
|
109 |
+
list_label_1.append(0)
|
110 |
+
list_point_2 = st.session_state.floor_point
|
111 |
+
for i in range(len(st.session_state.floor_point)):
|
112 |
+
list_label_2.append(0)
|
113 |
+
else:
|
114 |
+
list_point_1 = []
|
115 |
+
list_point_2 = []
|
116 |
+
list_point = list_point_1 + list_point_2
|
117 |
+
list_label = list_label_1 + list_label_2
|
118 |
+
print('list_point', list_point)
|
119 |
+
print('list_label', list_label)
|
120 |
+
point = pointdet(image_path , list_1,
|
121 |
+
points=list_point,
|
122 |
+
#points = [],
|
123 |
+
labels=list_label,
|
124 |
+
#labels = [],
|
125 |
+
use_space=True)
|
126 |
+
if point is not None:
|
127 |
+
st.session_state.point = point
|
128 |
+
st.session_state.floor_point = []
|
129 |
+
st.session_state.ceiling_point = []
|
130 |
+
#if 'points' not in st.session_state:
|
131 |
+
st.session_state.points = []
|
132 |
+
if point is not None:
|
133 |
+
for i in st.session_state.point:
|
134 |
+
if i['label_id'] == 0:
|
135 |
+
#st.session_state.ceiling_point.append([int(i['point'][0]), int(i['point'][1])])
|
136 |
+
st.session_state.points.append([int(i['point'][0]), int(i['point'][1])])
|
137 |
+
else:
|
138 |
+
#st.session_state.floor_point.append([int(i['point'][0]), int(i['point'][1])])
|
139 |
+
st.session_state.points.append([int(i['point'][0]), int(i['point'][1])])
|
140 |
+
print('st.session_state.points', st.session_state.points)
|
141 |
+
c_f_point = points_sorter(st.session_state.points)
|
142 |
+
st.session_state.ceiling_point = c_f_point[0]
|
143 |
+
st.session_state.floor_point = c_f_point[1]
|
144 |
+
#print('a', a)
|
145 |
+
#st.session_state.ceiling_point = sort_list_ceiling(st.session_state.ceiling_point)
|
146 |
+
print(st.session_state.ceiling_point)
|
147 |
+
#st.session_state.floor_point = sort_list_floor(st.session_state.floor_point)
|
148 |
+
#st.session_state.ceiling_point = cv2.convexHull(np.array(st.session_state.ceiling_point))
|
149 |
+
#st.session_state.floor_point = cv2.convexHull(np.array(st.session_state.floor_point))
|
150 |
+
#print('st.session_state.ceiling_point', st.session_state.ceiling_point)
|
151 |
+
#print('st.session_state.floor_point', st.session_state.floor_point)
|
152 |
+
#st.rerun()
|
153 |
+
def sort_list_ceiling(no_change_list):
|
154 |
+
if len(no_change_list) >= 4:
|
155 |
+
no_change_list.sort()
|
156 |
+
if no_change_list[0][1] > no_change_list[1][1]:
|
157 |
+
no_change_list[0], no_change_list[1] = no_change_list[1], no_change_list[0]
|
158 |
+
if no_change_list[-1][1] > no_change_list[-2][1]:
|
159 |
+
no_change_list[-1], no_change_list[-2] = no_change_list[-2], no_change_list[-1]
|
160 |
+
if len(no_change_list) == 3:
|
161 |
+
no_change_list.sort()
|
162 |
+
if no_change_list[0][1] > no_change_list[1][1]:
|
163 |
+
no_change_list[0], no_change_list[1] = no_change_list[1], no_change_list[0]
|
164 |
+
return no_change_list
|
165 |
+
def sort_list_floor(no_change_list):
|
166 |
+
if len(no_change_list) >= 4:
|
167 |
+
no_change_list.sort()
|
168 |
+
if no_change_list[0][1] < no_change_list[1][1]:
|
169 |
+
no_change_list[0], no_change_list[1] = no_change_list[1], no_change_list[0]
|
170 |
+
if no_change_list[-1][1] < no_change_list[-2][1]:
|
171 |
+
no_change_list[-1], no_change_list[-2] = no_change_list[-2], no_change_list[-1]
|
172 |
+
if len(no_change_list) == 3:
|
173 |
+
no_change_list.sort()
|
174 |
+
if no_change_list[0][1] < no_change_list[1][1]:
|
175 |
+
no_change_list[0], no_change_list[1] = no_change_list[1], no_change_list[0]
|
176 |
+
return no_change_list
|
177 |
+
#@st.dialog('Определение углов комнаты', width='large')
|
178 |
+
def corner_change(image_path):
|
179 |
+
list_1 = ['Угол потолка', 'Угол пола']
|
180 |
+
list_label_1 = []
|
181 |
+
list_label_2 = []
|
182 |
+
list_point_1 = []
|
183 |
+
list_point_2 = []
|
184 |
+
if 'ceiling_point' in st.session_state and 'floor_point' in st.session_state and st.session_state.ceiling_point is not None and st.session_state.floor_point is not None:
|
185 |
+
list_point_1 = st.session_state.ceiling_point
|
186 |
+
for i in range(len(st.session_state.ceiling_point)):
|
187 |
+
list_label_1.append(0)
|
188 |
+
list_point_2 = st.session_state.floor_point
|
189 |
+
for i in range(len(st.session_state.floor_point)):
|
190 |
+
list_label_2.append(1)
|
191 |
+
else:
|
192 |
+
list_point_1 = []
|
193 |
+
list_point_2 = []
|
194 |
+
list_point = list_point_1 + list_point_2
|
195 |
+
list_label = list_label_1 + list_label_2
|
196 |
+
print('list_point', list_point)
|
197 |
+
print('list_label', list_label)
|
198 |
+
point = pointdet(image_path , list_1,
|
199 |
+
points=list_point,
|
200 |
+
#points = [],
|
201 |
+
labels=list_label,
|
202 |
+
#labels = [],
|
203 |
+
use_space=True)
|
204 |
+
if point is not None:
|
205 |
+
st.session_state.point = point
|
206 |
+
st.session_state.floor_point = []
|
207 |
+
st.session_state.ceiling_point = []
|
208 |
+
|
209 |
+
if point is not None:
|
210 |
+
for i in st.session_state.point:
|
211 |
+
if i['label_id'] == 0:
|
212 |
+
|
213 |
+
st.session_state.ceiling_point.append([int(i['point'][0]), int(i['point'][1])])
|
214 |
+
else:
|
215 |
+
st.session_state.floor_point.append([int(i['point'][0]), int(i['point'][1])])
|
216 |
+
st.session_state.ceiling_point = sort_list_ceiling(st.session_state.ceiling_point)
|
217 |
+
print(st.session_state.ceiling_point)
|
218 |
+
st.session_state.floor_point = sort_list_floor(st.session_state.floor_point)
|
219 |
+
#st.session_state.ceiling_point = cv2.convexHull(np.array(st.session_state.ceiling_point))
|
220 |
+
#st.session_state.floor_point = cv2.convexHull(np.array(st.session_state.floor_point))
|
221 |
+
print('st.session_state.ceiling_point', st.session_state.ceiling_point)
|
222 |
+
print('st.session_state.floor_point', st.session_state.floor_point)
|
223 |
+
#st.rerun()
|
224 |
+
return point
|
225 |
+
@st.dialog("modification_photo")
|
226 |
+
def modification_photo(image_1):
|
227 |
+
st.session_state.modification_photo = [image_1]
|
228 |
+
st.rerun()
|
229 |
+
def a(path_photo):
|
230 |
+
st.session_state.a = path_photo
|
231 |
+
def predict(path_photo, model):
|
232 |
+
path_file =save_file_st(path_photo)
|
233 |
+
_, seg_map, seg_all, image = moduls.model.predict_and_visualize(model, path_file)
|
234 |
+
print(seg_map.shape)
|
235 |
+
st.session_state.predict =[seg_all, image]
|
236 |
+
contur_image, simplified_contour = conturs_on_image(image, seg_map)
|
237 |
+
st.session_state.contur_image =contur_image
|
238 |
+
st.session_state.simplified_contour = simplified_contour
|
239 |
+
return image
|
240 |
+
def modificate_image(surface):
|
241 |
+
original_img = cv2.cvtColor(st.session_state.predict[1], cv2.COLOR_BGR2RGB)
|
242 |
+
if st.session_state.f_h !=0:
|
243 |
+
f_h = st.session_state.f_h
|
244 |
+
else:
|
245 |
+
f_h = None
|
246 |
+
if st.session_state.w_h !=0:
|
247 |
+
w_h = st.session_state.w_h
|
248 |
+
else:
|
249 |
+
w_h = None
|
250 |
+
if st.session_state.c_h !=0:
|
251 |
+
c_h = st.session_state.c_h
|
252 |
+
else:
|
253 |
+
c_h = None
|
254 |
+
image_1 = texture_transformation_1(original_img, st.session_state.predict[0],
|
255 |
+
st.session_state.room_l*100, st.session_state.room_w*100, st.session_state.room_h*100,
|
256 |
+
st.session_state.ceiling_point, st.session_state.floor_point,
|
257 |
+
st.session_state.floor_angel, st.session_state.wall_angel, st.session_state.ceiling_angel,
|
258 |
+
st.session_state.json_list, surface = st.session_state.surface,
|
259 |
+
h_f= f_h, h_w = w_h, h_c = c_h,
|
260 |
+
rescale = 1.)
|
261 |
+
st.session_state.image_1 = image_1
|
262 |
+
st.session_state.modification_photo = [image_1]
|
263 |
+
def save_angel():
|
264 |
+
st.session_state.floor_angel = floor_angel
|
265 |
+
st.session_state.ceiling_angel = ceiling_angel
|
266 |
+
st.session_state.wall_angel = wall_angel
|
267 |
+
path_icon, path_json, path_logo = path_for_streamlit()
|
268 |
+
if 'json_list' not in st.session_state:
|
269 |
+
st.session_state.json_list = [None, None, None]
|
270 |
+
img_list_1 = []
|
271 |
+
img_list = []
|
272 |
+
for path_file in os.listdir(path_icon):
|
273 |
+
img_list_1.append(path_icon + f'\{path_file}')
|
274 |
+
for path_json_file in os.listdir(path_json):
|
275 |
+
if path_json_file.endswith(('.json')):
|
276 |
+
img_list.append(path_json + f'\{path_json_file}')
|
277 |
+
img_list_1.sort()
|
278 |
+
img_list.sort()
|
279 |
+
title_col1, title_col2 = st.columns([1,3])
|
280 |
+
with title_col1:
|
281 |
+
st.image(path_logo)
|
282 |
+
with title_col2:
|
283 |
+
st.title(":orange[Замена текстур на фотографии вашей комнаты]",)
|
284 |
+
|
285 |
+
change_col_1, change_col_2, change_col_3 = st.columns([1, 4, 1])
|
286 |
+
# Загрузка фотографиии
|
287 |
+
with change_col_1:
|
288 |
+
path_photo = st.file_uploader("Загрузка фото", type=['png','jpeg','jpg'], accept_multiple_files=False, key=None,
|
289 |
+
help=None, on_change=None, args=None, kwargs=None,
|
290 |
+
disabled=False, label_visibility = 'collapsed')
|
291 |
+
if path_photo == None:
|
292 |
+
st.session_state.a = None
|
293 |
+
st.session_state.pp = None
|
294 |
+
if path_photo is not None:
|
295 |
+
if st.session_state.a != path_photo:
|
296 |
+
st.session_state.ceiling_point = None
|
297 |
+
st.session_state.floor_point = None
|
298 |
+
st.session_state.pp = None
|
299 |
+
st.session_state.a = path_photo
|
300 |
+
predict(st.session_state.a, model)
|
301 |
+
st.session_state.modification_photo = [cv2.cvtColor(st.session_state.predict[1], cv2.COLOR_BGR2RGB)]
|
302 |
+
# Выбор угловых точек на фотографии
|
303 |
+
with change_col_2:
|
304 |
+
if path_photo is not None:
|
305 |
+
cv2.imwrite('corners.png',st.session_state.contur_image)
|
306 |
+
#st.session_state.corners = corner_change('corners.png')
|
307 |
+
st.session_state.corners = corner_change_2('corners.png')
|
308 |
+
# Размеры комнаты и выбор способа набора текстуры
|
309 |
+
with change_col_3:
|
310 |
+
if path_photo is not None:
|
311 |
+
st.session_state.room_l = st.number_input('Глубина комнаты', min_value=0., max_value=6., value=4., step=0.1, format=None, key='room_l_key', help=None, on_change=None, args=None, kwargs=None, placeholder=None, disabled=False, label_visibility="visible")
|
312 |
+
st.session_state.room_w = st.number_input('Ширина комнаты', min_value=0., max_value=6., value=3., step=0.1, format=None, key='room_w_key', help=None, on_change=None, args=None, kwargs=None, placeholder=None, disabled=False, label_visibility="visible")
|
313 |
+
st.session_state.room_h = st.number_input('Высота потолка', min_value=0., max_value=4., value=3., step=0.1, format=None, key='room_h_key', help=None, on_change=None, args=None, kwargs=None, placeholder=None, disabled=False, label_visibility="visible")
|
314 |
+
# Выбор текстур
|
315 |
+
if 'corners' in st.session_state and st.session_state.corners != None:
|
316 |
+
st.session_state.pp = 1
|
317 |
+
col1, col2, col3 = st.columns(3)
|
318 |
+
# Текстура пола
|
319 |
+
with col1:
|
320 |
+
if path_photo is not None and st.session_state.pp is not None:
|
321 |
+
floor = st.checkbox('Текстура пола', value=False, key=None, help=None, on_change=None, args=None, kwargs=None, disabled=False, label_visibility="visible")
|
322 |
+
if floor:
|
323 |
+
floor_select = st.button("Выбор текстуры пола", key = '1')
|
324 |
+
if floor_select:
|
325 |
+
select_floor(img_list_1, cv2.cvtColor(st.session_state.modification_photo[0], cv2.COLOR_BGR2RGB), img_list)
|
326 |
+
try:
|
327 |
+
st.image(img_list_1[st.session_state.select_floor[0]], caption=None, width=200, use_column_width=None, clamp=False, channels='RGB', output_format="auto")
|
328 |
+
st.session_state.json_list[0] = img_list[st.session_state.select_floor[0]]
|
329 |
+
except:
|
330 |
+
b=1
|
331 |
+
else:
|
332 |
+
st.session_state.json_list[0] = None
|
333 |
+
# Текстура стен
|
334 |
+
with col2:
|
335 |
+
if path_photo is not None and st.session_state.pp is not None:
|
336 |
+
wall = st.checkbox('Текстура стен', value=False, key=None, help=None, on_change=None, args=None, kwargs=None, disabled=False, label_visibility="visible")
|
337 |
+
if wall:
|
338 |
+
wall_select = st.button("Выбор текстуры стен", key = '2')
|
339 |
+
if wall_select:
|
340 |
+
select_wall(img_list_1, cv2.cvtColor(st.session_state.modification_photo[0], cv2.COLOR_BGR2RGB), img_list)
|
341 |
+
try:
|
342 |
+
st.image(img_list_1[st.session_state.select_wall[0]], caption=None, width=200, use_column_width=None, clamp=False, channels='RGB', output_format="auto")
|
343 |
+
st.session_state.json_list[1] = img_list[st.session_state.select_wall[0]]
|
344 |
+
except:
|
345 |
+
b=1
|
346 |
+
else:
|
347 |
+
st.session_state.json_list[1] = None
|
348 |
+
# Текстура потолка
|
349 |
+
with col3:
|
350 |
+
if path_photo is not None and st.session_state.pp is not None:
|
351 |
+
ceiling = st.checkbox('Текстура потолка', value=False, key=None, help=None, on_change=None, args=None, kwargs=None, disabled=False, label_visibility="visible")
|
352 |
+
if ceiling:
|
353 |
+
ceiling_select = st.button("Выбор текстуры потолка", key = '3')
|
354 |
+
if ceiling_select:
|
355 |
+
select_ceiling(img_list_1, cv2.cvtColor(st.session_state.modification_photo[0], cv2.COLOR_BGR2RGB), img_list)
|
356 |
+
try:
|
357 |
+
st.image(img_list_1[st.session_state.select_ceiling[0]], caption=None, width=200, use_column_width=None, clamp=False, channels='RGB', output_format="auto")
|
358 |
+
st.session_state.json_list[2] = img_list[st.session_state.select_ceiling[0]]
|
359 |
+
except:
|
360 |
+
b=1
|
361 |
+
else:
|
362 |
+
st.session_state.json_list[2] = None
|
363 |
+
if path_photo is not None and st.session_state.pp is not None:
|
364 |
+
st.session_state.surface = [floor, wall, ceiling]
|
365 |
+
|
366 |
+
# Выбор углов поворота текстур
|
367 |
+
col1_1, col2_1 = st.columns([3,1])
|
368 |
+
try:
|
369 |
+
with col2_1:
|
370 |
+
if path_photo is not None and st.session_state.pp is not None:
|
371 |
+
floor_angel = st.slider(label = 'Угол поворота текстуры пола',min_value=0, max_value=360, value=0, step=1, format=None, key='floor_angle_key',
|
372 |
+
help=None, on_change=save_angel, args=None, kwargs=None, disabled=False, label_visibility= 'visible')
|
373 |
+
wall_angel = st.slider(label = 'Угол поворота текстуры стен',min_value=0, max_value=360, value=0, step=1, format=None, key='wall_angle_key',
|
374 |
+
help=None, on_change=save_angel, args=None, kwargs=None, disabled=False, label_visibility= 'visible')
|
375 |
+
ceiling_angel = st.slider(label = 'Угол поворота текстуры потолка',min_value=0, max_value=360, value=0, step=1, format=None, key='ceiling_angle_key',
|
376 |
+
help=None, on_change=save_angel, args=None, kwargs=None, disabled=False, label_visibility= 'visible')
|
377 |
+
st.write(":orange[Выбор способа набора текстур]")
|
378 |
+
st.write(":orange[Если больше 1 то набор ёлочкой]")
|
379 |
+
st.session_state.f_h = st.number_input('Пол', min_value=0, max_value=3, value=0, step=1, format=None, key='f_h_key', help=None, on_change=None, args=None, kwargs=None, placeholder=None, disabled=False, label_visibility="visible")
|
380 |
+
st.session_state.w_h = st.number_input('Стены', min_value=0, max_value=3, value=0, step=1, format=None, key='w_h_key', help=None, on_change=None, args=None, kwargs=None, placeholder=None, disabled=False, label_visibility="visible")
|
381 |
+
st.session_state.c_h = st.number_input('Потолок', min_value=0, max_value=3, value=0, step=1, format=None, key='c_h_key', help=None, on_change=None, args=None, kwargs=None, placeholder=None, disabled=False, label_visibility="visible")
|
382 |
+
|
383 |
+
if 'floor_angel' not in st.session_state:
|
384 |
+
st.session_state.floor_angel = 0
|
385 |
+
if 'wall_angel' not in st.session_state:
|
386 |
+
st.session_state.wall_angel = 0
|
387 |
+
if 'ceiling_angel' not in st.session_state:
|
388 |
+
st.session_state.ceiling_angel = 0
|
389 |
+
try:
|
390 |
+
if st.session_state.floor_angel != floor_angel:
|
391 |
+
modificate_image('floor')
|
392 |
+
except:
|
393 |
+
print('no_change_angel_floor')
|
394 |
+
try:
|
395 |
+
if st.session_state.wall_angel != wall_angel:
|
396 |
+
modificate_image('floor')
|
397 |
+
except:
|
398 |
+
print('no_change_angel_wall')
|
399 |
+
try:
|
400 |
+
if st.session_state.ceiling_angel != ceiling_angel:
|
401 |
+
modificate_image('ceiling')
|
402 |
+
except:
|
403 |
+
print('no_change_angel_ceiling')
|
404 |
+
|
405 |
+
# Отображение фотографии с наложением текстур
|
406 |
+
with col1_1:
|
407 |
+
# scroll = st.slider(label = '123',min_value=0., max_value=1., value=0.5, step=0.01, format=None, key=33,
|
408 |
+
# help=None, on_change=None, args=None, kwargs=None, disabled=False, label_visibility= 'hidden')
|
409 |
+
if path_photo is not None and st.session_state.pp is not None:
|
410 |
+
if st.session_state.modification_photo is not None:
|
411 |
+
image_1 = st.session_state.modification_photo[0]
|
412 |
+
else:
|
413 |
+
image_1 = cv2.cvtColor(st.session_state.predict[1], cv2.COLOR_BGR2RGB)
|
414 |
+
image = cv2.cvtColor(st.session_state.predict[1], cv2.COLOR_BGR2RGB)
|
415 |
+
#st.write(st.get_option())
|
416 |
+
image_comparison(
|
417 |
+
img1=image,
|
418 |
+
img2=image_1,
|
419 |
+
width = 1080,
|
420 |
+
starting_position = 1
|
421 |
+
)
|
422 |
+
#fix_line = np.zeros((image.shape[0], 5, 3), dtype=np.uint8)
|
423 |
+
#fix_line[:,:,1] = 254
|
424 |
+
#image_2 =cv2.hconcat([image[:, 0:int(image.shape[1]*scroll)], fix_line])
|
425 |
+
#image_3 =cv2.hconcat([image_2, image_1[: , int(image_1.shape[1]*scroll+5):]])
|
426 |
+
#img = st.image(image_3, caption=None, use_column_width='always', clamp=False, channels="RGB", output_format="auto")
|
427 |
+
cv2.imwrite('Change_photo.jpg', cv2.cvtColor(st.session_state.modification_photo[0], cv2.COLOR_BGR2RGB))
|
428 |
+
with open('Change_photo.jpg', "rb") as file:
|
429 |
+
print(type(file))
|
430 |
+
btn = st.download_button(
|
431 |
+
label="Скачать изображение с наложенной текстурой",
|
432 |
+
data=file,
|
433 |
+
file_name="Change_photo.png",
|
434 |
+
mime="image/png"
|
435 |
+
)
|
436 |
+
except:
|
437 |
+
b=1
|
438 |
+
|