Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Command-line interface for lane detection | |
| Usage: python cli.py <input_video> <output_video> [method] [enhanced] [segmented] | |
| """ | |
| import sys | |
| import os | |
| from lane_detection import process_video | |
| def main(): | |
| if len(sys.argv) < 3 or len(sys.argv) > 6: | |
| print("Usage: python cli.py <input_video> <output_video> [method] [enhanced] [segmented]") | |
| print("\nArguments:") | |
| print(" input_video: Path to input video file") | |
| print(" output_video: Path to output video file") | |
| print(" method: 'basic_standard', 'basic_segmented', 'advanced', 'yolop', 'ufld', or 'scnn' (default: advanced)") | |
| print(" enhanced: 'true' or 'false' for enhanced thresholding (default: true, advanced only)") | |
| print(" segmented: 'true' or 'false' for segmented lines (default: false, basic only)") | |
| print("\nExamples:") | |
| print(" python cli.py road_video.mp4 output_result.mp4") | |
| print(" python cli.py road_video.mp4 output_result.mp4 yolop") | |
| print(" python cli.py road_video.mp4 output_result.mp4 ufld") | |
| print(" python cli.py road_video.mp4 output_result.mp4 scnn") | |
| print(" python cli.py road_video.mp4 output_result.mp4 basic_standard") | |
| print(" python cli.py road_video.mp4 output_result.mp4 basic_segmented") | |
| print(" python cli.py road_video.mp4 output_result.mp4 advanced true false") | |
| sys.exit(1) | |
| input_path = sys.argv[1] | |
| output_path = sys.argv[2] | |
| method = sys.argv[3] if len(sys.argv) >= 4 else "advanced" | |
| enhanced = sys.argv[4].lower() == "true" if len(sys.argv) >= 5 else True | |
| segmented = sys.argv[5].lower() == "true" if len(sys.argv) >= 6 else False | |
| # Validate method | |
| valid_methods = ["basic_standard", "basic_segmented", "advanced", "yolop", "ufld", "scnn"] | |
| if method not in valid_methods: | |
| print(f"Error: Invalid method '{method}'. Use one of: {', '.join(valid_methods)}") | |
| sys.exit(1) | |
| # Check if input file exists | |
| if not os.path.exists(input_path): | |
| print(f"Error: Input file '{input_path}' not found!") | |
| sys.exit(1) | |
| print(f"Processing video: {input_path}") | |
| print(f"Output will be saved to: {output_path}") | |
| print(f"Method: {method}") | |
| if method == "advanced": | |
| print(f"Enhanced thresholding: {'enabled' if enhanced else 'disabled'}") | |
| if method in ["basic_standard", "basic_segmented"]: | |
| print(f"Segmented lines: {'enabled' if segmented else 'disabled'}") | |
| print("\nProcessing...") | |
| try: | |
| success = process_video(input_path, output_path, method, enhanced, segmented) | |
| if success: | |
| print("\nβ Video processing completed successfully!") | |
| print(f"β Result saved to: {output_path}") | |
| if os.path.exists(output_path): | |
| size = os.path.getsize(output_path) | |
| print(f"β File size: {size:,} bytes") | |
| else: | |
| print("\nβ Video processing failed!") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"\nβ Error during processing: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| try: | |
| main() | |
| except KeyboardInterrupt: | |
| print("\n\nOperation cancelled by user.") | |
| sys.exit(0) | |
| except Exception as e: | |
| print(f"\nβ Unexpected error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) | |