shaded tiles
Browse files- app.py +2 -2
- inference_tab/inference_setup.py +43 -12
app.py
CHANGED
|
@@ -21,7 +21,7 @@ with gr.Blocks() as demo:
|
|
| 21 |
|
| 22 |
|
| 23 |
# Autofocus JavaScript: put cursor into Transcription box
|
| 24 |
-
|
| 25 |
None,
|
| 26 |
None,
|
| 27 |
_js="""
|
|
@@ -35,7 +35,7 @@ with gr.Blocks() as demo:
|
|
| 35 |
}, 100);
|
| 36 |
}
|
| 37 |
"""
|
| 38 |
-
)
|
| 39 |
|
| 40 |
|
| 41 |
# [DEBUG]
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
# Autofocus JavaScript: put cursor into Transcription box
|
| 24 |
+
''' demo.load(
|
| 25 |
None,
|
| 26 |
None,
|
| 27 |
_js="""
|
|
|
|
| 35 |
}, 100);
|
| 36 |
}
|
| 37 |
"""
|
| 38 |
+
)'''
|
| 39 |
|
| 40 |
|
| 41 |
# [DEBUG]
|
inference_tab/inference_setup.py
CHANGED
|
@@ -7,7 +7,7 @@ import os
|
|
| 7 |
TILE_SIZE = 1024
|
| 8 |
TILE_FOLDER = "tiles"
|
| 9 |
os.makedirs(TILE_FOLDER, exist_ok=True)
|
| 10 |
-
tiles_cache = {"tiles": [], "selected_tile": None}
|
| 11 |
|
| 12 |
|
| 13 |
def make_tiles(image, tile_size=TILE_SIZE):
|
|
@@ -23,6 +23,17 @@ def make_tiles(image, tile_size=TILE_SIZE):
|
|
| 23 |
cv2.rectangle(annotated, (x, y), (x+tile_size, y+tile_size), (255,0,0), 2)
|
| 24 |
cv2.putText(annotated, str(tile_id), (x+50, y+50),
|
| 25 |
cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,0), 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
tile_id += 1
|
| 27 |
return annotated, tiles
|
| 28 |
|
|
@@ -55,12 +66,14 @@ def select_tile(evt: gr.SelectData,state):
|
|
| 55 |
# store the path, not the array
|
| 56 |
tiles_cache["selected_tile"] = {
|
| 57 |
"tile_path": tile_path,
|
| 58 |
-
"coords": coords
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
updated_state = {
|
| 62 |
"tile_path": tile_path,
|
| 63 |
-
"coords": coords
|
|
|
|
| 64 |
}
|
| 65 |
|
| 66 |
# load tile only for display
|
|
@@ -74,6 +87,17 @@ def select_tile(evt: gr.SelectData,state):
|
|
| 74 |
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def get_inference_widgets(run_inference,georefImg):
|
|
@@ -102,22 +126,30 @@ def get_inference_widgets(run_inference,georefImg):
|
|
| 102 |
output = gr.Textbox(label="Progress", lines=5, interactive=False)
|
| 103 |
download_file = gr.File(label="Download CSV")
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
|
| 108 |
# Wire events
|
| 109 |
create_btn.click(
|
| 110 |
-
fn=
|
|
|
|
| 111 |
outputs=[annotated_out, run_button]
|
| 112 |
)
|
|
|
|
| 113 |
annotated_out.select(
|
| 114 |
-
fn=select_tile,
|
| 115 |
-
|
|
|
|
| 116 |
)
|
|
|
|
| 117 |
run_button.click(
|
| 118 |
-
fn=
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
)
|
| 122 |
|
| 123 |
georef_btn.click(
|
|
@@ -126,5 +158,4 @@ def get_inference_widgets(run_inference,georefImg):
|
|
| 126 |
outputs=[output]
|
| 127 |
)
|
| 128 |
|
| 129 |
-
|
| 130 |
return image_input, gcp_input, city_name, score_th, run_button, output, download_file
|
|
|
|
| 7 |
TILE_SIZE = 1024
|
| 8 |
TILE_FOLDER = "tiles"
|
| 9 |
os.makedirs(TILE_FOLDER, exist_ok=True)
|
| 10 |
+
tiles_cache = {"tiles": [], "selected_tile": None,"processed_tiles": set()}
|
| 11 |
|
| 12 |
|
| 13 |
def make_tiles(image, tile_size=TILE_SIZE):
|
|
|
|
| 23 |
cv2.rectangle(annotated, (x, y), (x+tile_size, y+tile_size), (255,0,0), 2)
|
| 24 |
cv2.putText(annotated, str(tile_id), (x+50, y+50),
|
| 25 |
cv2.FONT_HERSHEY_SIMPLEX, 2, (0,0,0), 5)
|
| 26 |
+
|
| 27 |
+
# Shade tile if already processed
|
| 28 |
+
if tile_id in tiles_cache["processed_tiles"]:
|
| 29 |
+
overlay = annotated[y:y+tile_size, x:x+tile_size].copy()
|
| 30 |
+
overlay[:] = (0, 255, 0) # light green
|
| 31 |
+
alpha = 0.4
|
| 32 |
+
annotated[y:y+tile_size, x:x+tile_size] = cv2.addWeighted(
|
| 33 |
+
overlay, alpha, annotated[y:y+tile_size, x:x+tile_size], 1-alpha, 0
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
tile_id += 1
|
| 38 |
return annotated, tiles
|
| 39 |
|
|
|
|
| 66 |
# store the path, not the array
|
| 67 |
tiles_cache["selected_tile"] = {
|
| 68 |
"tile_path": tile_path,
|
| 69 |
+
"coords": coords,
|
| 70 |
+
"tile_id": tile_id
|
| 71 |
}
|
| 72 |
|
| 73 |
updated_state = {
|
| 74 |
"tile_path": tile_path,
|
| 75 |
+
"coords": coords,
|
| 76 |
+
"tile_id": tile_id
|
| 77 |
}
|
| 78 |
|
| 79 |
# load tile only for display
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
+
# ---- Mark a tile as processed and update annotated output ----
|
| 91 |
+
def mark_tile_processed(original_image):
|
| 92 |
+
tile_info = tiles_cache.get("selected_tile")
|
| 93 |
+
if not tile_info:
|
| 94 |
+
return original_image
|
| 95 |
+
|
| 96 |
+
tile_id = tile_info["tile_id"]
|
| 97 |
+
tiles_cache["processed_tiles"].add(tile_id)
|
| 98 |
+
|
| 99 |
+
annotated, _ = make_tiles(original_image, TILE_SIZE)
|
| 100 |
+
return annotated
|
| 101 |
|
| 102 |
|
| 103 |
def get_inference_widgets(run_inference,georefImg):
|
|
|
|
| 126 |
output = gr.Textbox(label="Progress", lines=5, interactive=False)
|
| 127 |
download_file = gr.File(label="Download CSV")
|
| 128 |
|
| 129 |
+
selected_tile_state = gr.State()
|
| 130 |
+
original_image_state = gr.State()
|
| 131 |
|
| 132 |
# Wire events
|
| 133 |
create_btn.click(
|
| 134 |
+
fn=lambda file: (np.array(Image.open(file.name).convert("RGB")), gr.update(interactive=False)),
|
| 135 |
+
inputs=image_input,
|
| 136 |
outputs=[annotated_out, run_button]
|
| 137 |
)
|
| 138 |
+
|
| 139 |
annotated_out.select(
|
| 140 |
+
fn=select_tile,
|
| 141 |
+
inputs=[selected_tile_state],
|
| 142 |
+
outputs=[selected_tile, run_button, selected_tile_state]
|
| 143 |
)
|
| 144 |
+
|
| 145 |
run_button.click(
|
| 146 |
+
fn=lambda state, gcp, city, threshold: (
|
| 147 |
+
mark_tile_processed(np.array(Image.open(state["tile_path"]).convert("RGB"))),
|
| 148 |
+
"Tile processed",
|
| 149 |
+
None
|
| 150 |
+
),
|
| 151 |
+
inputs=[selected_tile_state, gcp_input, city_name, score_th],
|
| 152 |
+
outputs=[annotated_out, output, download_file]
|
| 153 |
)
|
| 154 |
|
| 155 |
georef_btn.click(
|
|
|
|
| 158 |
outputs=[output]
|
| 159 |
)
|
| 160 |
|
|
|
|
| 161 |
return image_input, gcp_input, city_name, score_th, run_button, output, download_file
|