Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,20 +41,17 @@ PATCHES_DIR = "patches"
|
|
| 41 |
PRED_PATCHES_DIR = "pred_patches"
|
| 42 |
CSV_LOG_PATH = "image_log.csv"
|
| 43 |
|
| 44 |
-
|
| 45 |
-
def split(image, destination = PATCHES_DIR, patch_size = 650):
|
| 46 |
img = cv2.imread(image)
|
| 47 |
-
h,w,_ = img.shape
|
| 48 |
for y in range(0, h, patch_size):
|
| 49 |
for x in range(0, w, patch_size):
|
| 50 |
patch = img[y:y+patch_size, x:x+patch_size]
|
| 51 |
-
|
| 52 |
-
|
| 53 |
patch_filename = f"patch_{y}_{x}.png"
|
| 54 |
patch_path = os.path.join(destination, patch_filename)
|
| 55 |
cv2.imwrite(patch_path, patch)
|
| 56 |
|
| 57 |
-
def merge(patch_folder
|
| 58 |
merged = np.zeros(image_shape[:-1] + (3,), dtype=np.uint8)
|
| 59 |
for filename in os.listdir(patch_folder):
|
| 60 |
if filename.endswith(".png"):
|
|
@@ -273,7 +270,7 @@ def upload_page():
|
|
| 273 |
else:
|
| 274 |
st.success('Image analyzed')
|
| 275 |
st.session_state.page = 'result'
|
| 276 |
-
st.
|
| 277 |
|
| 278 |
def result_page():
|
| 279 |
st.title('Analysis Result')
|
|
@@ -283,9 +280,7 @@ def result_page():
|
|
| 283 |
if st.button('Back to Upload'):
|
| 284 |
st.session_state.page = 'upload'
|
| 285 |
st.session_state.file_uploaded = False
|
| 286 |
-
st.
|
| 287 |
-
st.session_state.mask_filename = None
|
| 288 |
-
st.rerun()
|
| 289 |
return
|
| 290 |
|
| 291 |
col1, col2 = st.columns(2)
|
|
@@ -328,12 +323,9 @@ def result_page():
|
|
| 328 |
st.error("Image or mask file not found for overlay.")
|
| 329 |
|
| 330 |
if st.button('Back to Upload'):
|
| 331 |
-
|
| 332 |
st.session_state.page = 'upload'
|
| 333 |
st.session_state.file_uploaded = False
|
| 334 |
-
st.
|
| 335 |
-
st.session_state.mask_filename = None
|
| 336 |
-
st.rerun()
|
| 337 |
|
| 338 |
def main():
|
| 339 |
st.title('Building area estimation')
|
|
|
|
| 41 |
PRED_PATCHES_DIR = "pred_patches"
|
| 42 |
CSV_LOG_PATH = "image_log.csv"
|
| 43 |
|
| 44 |
+
def split(image, destination=PATCHES_DIR, patch_size=650):
|
|
|
|
| 45 |
img = cv2.imread(image)
|
| 46 |
+
h, w, _ = img.shape
|
| 47 |
for y in range(0, h, patch_size):
|
| 48 |
for x in range(0, w, patch_size):
|
| 49 |
patch = img[y:y+patch_size, x:x+patch_size]
|
|
|
|
|
|
|
| 50 |
patch_filename = f"patch_{y}_{x}.png"
|
| 51 |
patch_path = os.path.join(destination, patch_filename)
|
| 52 |
cv2.imwrite(patch_path, patch)
|
| 53 |
|
| 54 |
+
def merge(patch_folder, dest_image='out.png', image_shape=None):
|
| 55 |
merged = np.zeros(image_shape[:-1] + (3,), dtype=np.uint8)
|
| 56 |
for filename in os.listdir(patch_folder):
|
| 57 |
if filename.endswith(".png"):
|
|
|
|
| 270 |
else:
|
| 271 |
st.success('Image analyzed')
|
| 272 |
st.session_state.page = 'result'
|
| 273 |
+
st.experimental_rerun()
|
| 274 |
|
| 275 |
def result_page():
|
| 276 |
st.title('Analysis Result')
|
|
|
|
| 280 |
if st.button('Back to Upload'):
|
| 281 |
st.session_state.page = 'upload'
|
| 282 |
st.session_state.file_uploaded = False
|
| 283 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
| 284 |
return
|
| 285 |
|
| 286 |
col1, col2 = st.columns(2)
|
|
|
|
| 323 |
st.error("Image or mask file not found for overlay.")
|
| 324 |
|
| 325 |
if st.button('Back to Upload'):
|
|
|
|
| 326 |
st.session_state.page = 'upload'
|
| 327 |
st.session_state.file_uploaded = False
|
| 328 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
| 329 |
|
| 330 |
def main():
|
| 331 |
st.title('Building area estimation')
|