Spaces:
Sleeping
Sleeping
| import concurrent.futures | |
| from models import ( | |
| bridge_detector, encroachment_detector, structure_progress_detector, | |
| pothole_detector, crack_detector, unauthorized_median_detector, | |
| crash_barrier_detector, highway_exit_detector, drain_detector, | |
| tree_height_detector, latitude_detector, vari_detector | |
| ) | |
| from utils.video_utils import extract_frames | |
| model_map = { | |
| "Bridges": bridge_detector.run, | |
| "Encroachment": encroachment_detector.run, | |
| "Structure Progress": structure_progress_detector.run, | |
| "Potholes": pothole_detector.run, | |
| "Crack": crack_detector.run, | |
| "Unauthorized Median Opening": unauthorized_median_detector.run, | |
| "Crash Barriers": crash_barrier_detector.run, | |
| "Entry/Exit of Highway": highway_exit_detector.run, | |
| "Drain": drain_detector.run, | |
| "Tree Height": tree_height_detector.run, | |
| "Latitude": latitude_detector.run, | |
| "VARI": vari_detector.run | |
| } | |
| def process_video(video_file, selected_params): | |
| frames = extract_frames(video_file) | |
| results = {} | |
| with concurrent.futures.ThreadPoolExecutor() as executor: | |
| future_to_param = { | |
| executor.submit(model_map[param], frames): param for param in selected_params | |
| } | |
| for future in concurrent.futures.as_completed(future_to_param): | |
| param = future_to_param[future] | |
| results[param] = future.result() | |
| return [img for imgs in results.values() for img in imgs] | |