Update navigation/steering-angle.py
Browse files- navigation/steering-angle.py +33 -25
navigation/steering-angle.py
CHANGED
|
@@ -19,17 +19,17 @@ from utils.video_processor import profiler
|
|
| 19 |
if 'BASE_DIR' not in st.session_state:
|
| 20 |
from utils.helper import BASE_DIR,metrics_collection
|
| 21 |
st.session_state.BASE_DIR = BASE_DIR
|
| 22 |
-
print("BASE_DIR", BASE_DIR)
|
| 23 |
|
| 24 |
if 'metrics_collection' not in st.session_state:
|
| 25 |
from utils.helper import BASE_DIR,metrics_collection
|
| 26 |
st.session_state.metrics_collection = metrics_collection
|
| 27 |
-
print("metrics_collection", metrics_collection)
|
| 28 |
|
| 29 |
BASE_DIR = st.session_state.BASE_DIR
|
| 30 |
metrics_collection = st.session_state.metrics_collection
|
| 31 |
path_load_css = Path(BASE_DIR) / "assets" / "style.css"
|
| 32 |
-
print(path_load_css)
|
| 33 |
|
| 34 |
def load_css():
|
| 35 |
with open(Path(BASE_DIR) / "assets" / "style.css") as f:
|
|
@@ -104,7 +104,7 @@ with col2:
|
|
| 104 |
if 'start_dic' not in st.session_state:
|
| 105 |
st.session_state.start_dic = None
|
| 106 |
if 'postprocessing_mode' not in st.session_state:
|
| 107 |
-
st.session_state.
|
| 108 |
|
| 109 |
|
| 110 |
|
|
@@ -135,6 +135,7 @@ with col2:
|
|
| 135 |
|
| 136 |
if uploaded_file:
|
| 137 |
with st.spinner("Loading..."):
|
|
|
|
| 138 |
|
| 139 |
st.markdown("")
|
| 140 |
st.markdown("")
|
|
@@ -148,17 +149,17 @@ with col2:
|
|
| 148 |
|
| 149 |
if st.session_state.end_dic is None:
|
| 150 |
st.session_state.end_dic = st.session_state.video_processor.frames_list_end
|
| 151 |
-
print("End dic loaded:")
|
| 152 |
|
| 153 |
if st.session_state.start_dic is None:
|
| 154 |
st.session_state.start_dic = st.session_state.video_processor.frames_list_start
|
| 155 |
-
print("Start dic loaded:")
|
| 156 |
|
| 157 |
|
| 158 |
total_frames = st.session_state.video_processor.total_frames
|
| 159 |
original_fps = st.session_state.video_processor.fps
|
| 160 |
-
print("Original FPS:", original_fps)
|
| 161 |
-
print("Total frames:", total_frames)
|
| 162 |
|
| 163 |
|
| 164 |
|
|
@@ -232,8 +233,8 @@ with col2:
|
|
| 232 |
st.rerun()
|
| 233 |
|
| 234 |
|
| 235 |
-
print("Start frame helper:", st.session_state.end_frame_helper)
|
| 236 |
-
print("Start frame helper:", st.session_state.end_frame)
|
| 237 |
|
| 238 |
|
| 239 |
|
|
@@ -250,7 +251,7 @@ with col2:
|
|
| 250 |
if (st.session_state.start_preview is None or
|
| 251 |
st.session_state.start_frame_helper != st.session_state.start_frame):
|
| 252 |
try:
|
| 253 |
-
print("Getting start frame preview for frame:", st.session_state.start_frame_helper)
|
| 254 |
st.session_state.start_preview = st.session_state.start_dic[st.session_state.start_frame_helper]
|
| 255 |
# Actualizar también el valor de referencia en session_state
|
| 256 |
st.session_state.start_frame = st.session_state.start_frame_helper
|
|
@@ -259,7 +260,7 @@ with col2:
|
|
| 259 |
pass
|
| 260 |
|
| 261 |
if st.session_state.start_preview is not None:
|
| 262 |
-
print("Displaying start frame preview for frame:", st.session_state.start_frame_helper)
|
| 263 |
st.image(st.session_state.start_preview, caption=f"Start Frame: {st.session_state.start_frame_helper}", use_container_width=True)
|
| 264 |
|
| 265 |
# End frame preview
|
|
@@ -269,7 +270,7 @@ with col2:
|
|
| 269 |
if (st.session_state.end_preview is None or
|
| 270 |
st.session_state.end_frame_helper != st.session_state.end_frame):
|
| 271 |
try:
|
| 272 |
-
print("Getting end frame preview for frame:", st.session_state.end_frame_helper)
|
| 273 |
st.session_state.end_preview = st.session_state.end_dic[st.session_state.end_frame_helper]
|
| 274 |
# Actualizar también el valor de referencia en session_state
|
| 275 |
st.session_state.end_frame = st.session_state.end_frame_helper
|
|
@@ -323,7 +324,7 @@ with col2:
|
|
| 323 |
#('Verstappen 2025', 'Piastri 2025','Norris 2025','Leclerc 2025','Hamilton 2025','Russell 2025', 'Antonelli 2025', 'Tsunoda 2025')
|
| 324 |
|
| 325 |
|
| 326 |
-
driver_crop_type = st.session_state.
|
| 327 |
|
| 328 |
st.markdown("#### Step 3: Select Crop type 👈")
|
| 329 |
st.markdown("- Steering wheel, helmet and hands shold be visible, aim for acrop type like the example image.")
|
|
@@ -359,6 +360,8 @@ with col2:
|
|
| 359 |
if st.session_state.driver_crop_type != driver_crop_type:
|
| 360 |
|
| 361 |
st.session_state.btn = False
|
|
|
|
|
|
|
| 362 |
|
| 363 |
|
| 364 |
preview_cols1 = st.columns(2)
|
|
@@ -391,21 +394,23 @@ with col2:
|
|
| 391 |
|
| 392 |
st.markdown("#### Step 5: (Opcional) Postprocessing Settings")
|
| 393 |
st.markdown("- First try default mode, is the best for 90% of the cases")
|
|
|
|
| 394 |
|
| 395 |
#agregar opciones en radio para elegir el tipo de procesamiento
|
| 396 |
|
| 397 |
-
postprocessing_mode = st.radio(
|
| 398 |
"Select Postprocessing Mode",
|
| 399 |
options=["Default","Low ilumination"],
|
| 400 |
index=0,
|
| 401 |
help="Choose the postprocessing mode for the model",
|
| 402 |
horizontal=False
|
| 403 |
)
|
| 404 |
-
if postprocessing_mode != st.session_state.
|
| 405 |
|
| 406 |
st.session_state.btn = False
|
| 407 |
-
|
| 408 |
-
|
|
|
|
| 409 |
|
| 410 |
|
| 411 |
# Process button
|
|
@@ -416,17 +421,13 @@ with col2:
|
|
| 416 |
st.markdown("")
|
| 417 |
st.markdown("")
|
| 418 |
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
st.markdown("#### Step 4: Execute Model 🚀")
|
| 425 |
if st.button("Process Video Segment") or st.session_state.get('btn', True):
|
| 426 |
-
|
| 427 |
if not(st.session_state.get('btn', True)):
|
| 428 |
# Reset profiler before processing
|
| 429 |
profiler.reset()
|
|
|
|
| 430 |
#st.rerun() # Rerun to update the UI with the new value
|
| 431 |
|
| 432 |
with st.spinner("Processing frames..."):
|
|
@@ -435,7 +436,7 @@ with col2:
|
|
| 435 |
|
| 436 |
|
| 437 |
# Extract and process frames
|
| 438 |
-
st.session_state.video_processor.mode = postprocessing_mode
|
| 439 |
frames,crude_frames = st.session_state.video_processor.extract_frames(
|
| 440 |
st.session_state.start_frame_helper, st.session_state.end_frame_helper, fps_target=st.session_state.fps_target
|
| 441 |
)
|
|
@@ -470,6 +471,12 @@ with col2:
|
|
| 470 |
|
| 471 |
|
| 472 |
st.markdown("# Results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
| 474 |
display_results(df)
|
| 475 |
|
|
@@ -503,6 +510,7 @@ with col2:
|
|
| 503 |
|
| 504 |
|
| 505 |
else:
|
|
|
|
| 506 |
st.session_state.btn = False
|
| 507 |
try:
|
| 508 |
st.session_state.video_processor.clean_up() # Clear cache if no video is uploaded
|
|
|
|
| 19 |
if 'BASE_DIR' not in st.session_state:
|
| 20 |
from utils.helper import BASE_DIR,metrics_collection
|
| 21 |
st.session_state.BASE_DIR = BASE_DIR
|
| 22 |
+
#print("BASE_DIR", BASE_DIR)
|
| 23 |
|
| 24 |
if 'metrics_collection' not in st.session_state:
|
| 25 |
from utils.helper import BASE_DIR,metrics_collection
|
| 26 |
st.session_state.metrics_collection = metrics_collection
|
| 27 |
+
#print("metrics_collection", metrics_collection)
|
| 28 |
|
| 29 |
BASE_DIR = st.session_state.BASE_DIR
|
| 30 |
metrics_collection = st.session_state.metrics_collection
|
| 31 |
path_load_css = Path(BASE_DIR) / "assets" / "style.css"
|
| 32 |
+
#print(path_load_css)
|
| 33 |
|
| 34 |
def load_css():
|
| 35 |
with open(Path(BASE_DIR) / "assets" / "style.css") as f:
|
|
|
|
| 104 |
if 'start_dic' not in st.session_state:
|
| 105 |
st.session_state.start_dic = None
|
| 106 |
if 'postprocessing_mode' not in st.session_state:
|
| 107 |
+
st.session_state.postprocessing_mode = None
|
| 108 |
|
| 109 |
|
| 110 |
|
|
|
|
| 135 |
|
| 136 |
if uploaded_file:
|
| 137 |
with st.spinner("Loading..."):
|
| 138 |
+
print("Video uploaded")
|
| 139 |
|
| 140 |
st.markdown("")
|
| 141 |
st.markdown("")
|
|
|
|
| 149 |
|
| 150 |
if st.session_state.end_dic is None:
|
| 151 |
st.session_state.end_dic = st.session_state.video_processor.frames_list_end
|
| 152 |
+
#print("End dic loaded:")
|
| 153 |
|
| 154 |
if st.session_state.start_dic is None:
|
| 155 |
st.session_state.start_dic = st.session_state.video_processor.frames_list_start
|
| 156 |
+
#print("Start dic loaded:")
|
| 157 |
|
| 158 |
|
| 159 |
total_frames = st.session_state.video_processor.total_frames
|
| 160 |
original_fps = st.session_state.video_processor.fps
|
| 161 |
+
#print("Original FPS:", original_fps)
|
| 162 |
+
#print("Total frames:", total_frames)
|
| 163 |
|
| 164 |
|
| 165 |
|
|
|
|
| 233 |
st.rerun()
|
| 234 |
|
| 235 |
|
| 236 |
+
#print("Start frame helper:", st.session_state.end_frame_helper)
|
| 237 |
+
#print("Start frame helper:", st.session_state.end_frame)
|
| 238 |
|
| 239 |
|
| 240 |
|
|
|
|
| 251 |
if (st.session_state.start_preview is None or
|
| 252 |
st.session_state.start_frame_helper != st.session_state.start_frame):
|
| 253 |
try:
|
| 254 |
+
#print("Getting start frame preview for frame:", st.session_state.start_frame_helper)
|
| 255 |
st.session_state.start_preview = st.session_state.start_dic[st.session_state.start_frame_helper]
|
| 256 |
# Actualizar también el valor de referencia en session_state
|
| 257 |
st.session_state.start_frame = st.session_state.start_frame_helper
|
|
|
|
| 260 |
pass
|
| 261 |
|
| 262 |
if st.session_state.start_preview is not None:
|
| 263 |
+
#print("Displaying start frame preview for frame:", st.session_state.start_frame_helper)
|
| 264 |
st.image(st.session_state.start_preview, caption=f"Start Frame: {st.session_state.start_frame_helper}", use_container_width=True)
|
| 265 |
|
| 266 |
# End frame preview
|
|
|
|
| 270 |
if (st.session_state.end_preview is None or
|
| 271 |
st.session_state.end_frame_helper != st.session_state.end_frame):
|
| 272 |
try:
|
| 273 |
+
#print("Getting end frame preview for frame:", st.session_state.end_frame_helper)
|
| 274 |
st.session_state.end_preview = st.session_state.end_dic[st.session_state.end_frame_helper]
|
| 275 |
# Actualizar también el valor de referencia en session_state
|
| 276 |
st.session_state.end_frame = st.session_state.end_frame_helper
|
|
|
|
| 324 |
#('Verstappen 2025', 'Piastri 2025','Norris 2025','Leclerc 2025','Hamilton 2025','Russell 2025', 'Antonelli 2025', 'Tsunoda 2025')
|
| 325 |
|
| 326 |
|
| 327 |
+
driver_crop_type = st.session_state.driver_crop_type
|
| 328 |
|
| 329 |
st.markdown("#### Step 3: Select Crop type 👈")
|
| 330 |
st.markdown("- Steering wheel, helmet and hands shold be visible, aim for acrop type like the example image.")
|
|
|
|
| 360 |
if st.session_state.driver_crop_type != driver_crop_type:
|
| 361 |
|
| 362 |
st.session_state.btn = False
|
| 363 |
+
#st.session_state.driver_crop_type = driver_crop_type
|
| 364 |
+
|
| 365 |
|
| 366 |
|
| 367 |
preview_cols1 = st.columns(2)
|
|
|
|
| 394 |
|
| 395 |
st.markdown("#### Step 5: (Opcional) Postprocessing Settings")
|
| 396 |
st.markdown("- First try default mode, is the best for 90% of the cases")
|
| 397 |
+
postprocessing_mode = st.session_state.postprocessing_mode
|
| 398 |
|
| 399 |
#agregar opciones en radio para elegir el tipo de procesamiento
|
| 400 |
|
| 401 |
+
st.session_state.postprocessing_mode = st.radio(
|
| 402 |
"Select Postprocessing Mode",
|
| 403 |
options=["Default","Low ilumination"],
|
| 404 |
index=0,
|
| 405 |
help="Choose the postprocessing mode for the model",
|
| 406 |
horizontal=False
|
| 407 |
)
|
| 408 |
+
if postprocessing_mode != st.session_state.postprocessing_mode:
|
| 409 |
|
| 410 |
st.session_state.btn = False
|
| 411 |
+
#print("ininini")
|
| 412 |
+
|
| 413 |
+
#st.rerun() # Rerun to update the UI with the new value
|
| 414 |
|
| 415 |
|
| 416 |
# Process button
|
|
|
|
| 421 |
st.markdown("")
|
| 422 |
st.markdown("")
|
| 423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
st.markdown("#### Step 4: Execute Model 🚀")
|
| 425 |
if st.button("Process Video Segment") or st.session_state.get('btn', True):
|
| 426 |
+
|
| 427 |
if not(st.session_state.get('btn', True)):
|
| 428 |
# Reset profiler before processing
|
| 429 |
profiler.reset()
|
| 430 |
+
print("Processing video...")
|
| 431 |
#st.rerun() # Rerun to update the UI with the new value
|
| 432 |
|
| 433 |
with st.spinner("Processing frames..."):
|
|
|
|
| 436 |
|
| 437 |
|
| 438 |
# Extract and process frames
|
| 439 |
+
st.session_state.video_processor.mode = st.session_state.postprocessing_mode
|
| 440 |
frames,crude_frames = st.session_state.video_processor.extract_frames(
|
| 441 |
st.session_state.start_frame_helper, st.session_state.end_frame_helper, fps_target=st.session_state.fps_target
|
| 442 |
)
|
|
|
|
| 471 |
|
| 472 |
|
| 473 |
st.markdown("# Results")
|
| 474 |
+
st.markdown("")
|
| 475 |
+
#st.markdown("#### Download Results 📥")
|
| 476 |
+
#if st.button("Download Results (CSV)"):
|
| 477 |
+
# st.session_state.btn = True
|
| 478 |
+
# df.to_csv(str(st.session_state.driver_crop_type)+"_Steering_data_results.csv", index=False)
|
| 479 |
+
# st.info("Results downloaded successfully! you can find the file in your current directory.")
|
| 480 |
|
| 481 |
display_results(df)
|
| 482 |
|
|
|
|
| 510 |
|
| 511 |
|
| 512 |
else:
|
| 513 |
+
print("No video uploaded yet.")
|
| 514 |
st.session_state.btn = False
|
| 515 |
try:
|
| 516 |
st.session_state.video_processor.clean_up() # Clear cache if no video is uploaded
|