Spaces:
Sleeping
Sleeping
copilot-swe-agent[bot]
kr4phy
commited on
Commit
Β·
f4c30f7
1
Parent(s):
06417df
Fix cross-platform compatibility and add error handling
Browse filesCo-authored-by: kr4phy <168257476+kr4phy@users.noreply.github.com>
- cli.py +26 -11
- create_sample_images.py +6 -4
- quickstart.py +11 -3
cli.py
CHANGED
|
@@ -27,19 +27,34 @@ def main():
|
|
| 27 |
print(f"Output will be saved to: {output_path}")
|
| 28 |
print("\nProcessing...")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
if success:
|
| 33 |
-
print("\nβ Video processing completed successfully!")
|
| 34 |
-
print(f"β Result saved to: {output_path}")
|
| 35 |
|
| 36 |
-
if
|
| 37 |
-
|
| 38 |
-
print(f"β
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
sys.exit(1)
|
| 42 |
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
print(f"Output will be saved to: {output_path}")
|
| 28 |
print("\nProcessing...")
|
| 29 |
|
| 30 |
+
try:
|
| 31 |
+
success = process_video(input_path, output_path)
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
if success:
|
| 34 |
+
print("\nβ Video processing completed successfully!")
|
| 35 |
+
print(f"β Result saved to: {output_path}")
|
| 36 |
+
|
| 37 |
+
if os.path.exists(output_path):
|
| 38 |
+
size = os.path.getsize(output_path)
|
| 39 |
+
print(f"β File size: {size:,} bytes")
|
| 40 |
+
else:
|
| 41 |
+
print("\nβ Video processing failed!")
|
| 42 |
+
sys.exit(1)
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print(f"\nβ Error during processing: {e}")
|
| 45 |
+
import traceback
|
| 46 |
+
traceback.print_exc()
|
| 47 |
sys.exit(1)
|
| 48 |
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
+
try:
|
| 52 |
+
main()
|
| 53 |
+
except KeyboardInterrupt:
|
| 54 |
+
print("\n\nOperation cancelled by user.")
|
| 55 |
+
sys.exit(0)
|
| 56 |
+
except Exception as e:
|
| 57 |
+
print(f"\nβ Unexpected error: {e}")
|
| 58 |
+
import traceback
|
| 59 |
+
traceback.print_exc()
|
| 60 |
+
sys.exit(1)
|
create_sample_images.py
CHANGED
|
@@ -4,6 +4,7 @@ Create sample images to demonstrate lane detection
|
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def create_sample_frames():
|
|
@@ -13,8 +14,9 @@ def create_sample_frames():
|
|
| 13 |
from create_test_video import create_test_video
|
| 14 |
from lane_detection import process_video
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
# Create a test video with clear lanes
|
| 20 |
print("Creating demo video...")
|
|
@@ -39,7 +41,7 @@ def create_sample_frames():
|
|
| 39 |
|
| 40 |
if ret:
|
| 41 |
# Save the frame
|
| 42 |
-
output_path = "
|
| 43 |
cv2.imwrite(output_path, frame)
|
| 44 |
print(f"β Sample frame saved to: {output_path}")
|
| 45 |
print(f" Frame shows original (left) and lane detection (right)")
|
|
@@ -48,7 +50,7 @@ def create_sample_frames():
|
|
| 48 |
height, width = frame.shape[:2]
|
| 49 |
scale = 0.5
|
| 50 |
small_frame = cv2.resize(frame, (int(width * scale), int(height * scale)))
|
| 51 |
-
small_output_path = "
|
| 52 |
cv2.imwrite(small_output_path, small_frame)
|
| 53 |
print(f"β Smaller version saved to: {small_output_path}")
|
| 54 |
else:
|
|
|
|
| 4 |
import cv2
|
| 5 |
import numpy as np
|
| 6 |
import os
|
| 7 |
+
import tempfile
|
| 8 |
|
| 9 |
|
| 10 |
def create_sample_frames():
|
|
|
|
| 14 |
from create_test_video import create_test_video
|
| 15 |
from lane_detection import process_video
|
| 16 |
|
| 17 |
+
temp_dir = tempfile.gettempdir()
|
| 18 |
+
input_video = os.path.join(temp_dir, "demo_input.mp4")
|
| 19 |
+
output_video = os.path.join(temp_dir, "demo_output.mp4")
|
| 20 |
|
| 21 |
# Create a test video with clear lanes
|
| 22 |
print("Creating demo video...")
|
|
|
|
| 41 |
|
| 42 |
if ret:
|
| 43 |
# Save the frame
|
| 44 |
+
output_path = os.path.join(temp_dir, "lane_detection_demo.png")
|
| 45 |
cv2.imwrite(output_path, frame)
|
| 46 |
print(f"β Sample frame saved to: {output_path}")
|
| 47 |
print(f" Frame shows original (left) and lane detection (right)")
|
|
|
|
| 50 |
height, width = frame.shape[:2]
|
| 51 |
scale = 0.5
|
| 52 |
small_frame = cv2.resize(frame, (int(width * scale), int(height * scale)))
|
| 53 |
+
small_output_path = os.path.join(temp_dir, "lane_detection_demo_small.png")
|
| 54 |
cv2.imwrite(small_output_path, small_frame)
|
| 55 |
print(f"β Smaller version saved to: {small_output_path}")
|
| 56 |
else:
|
quickstart.py
CHANGED
|
@@ -5,6 +5,7 @@ Creates a test video, processes it, and verifies the output
|
|
| 5 |
"""
|
| 6 |
import os
|
| 7 |
import sys
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def main():
|
|
@@ -35,8 +36,9 @@ def main():
|
|
| 35 |
print("2. Creating test video...")
|
| 36 |
from create_test_video import create_test_video
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
|
| 41 |
create_test_video(input_video, duration_sec=2, fps=15)
|
| 42 |
print()
|
|
@@ -77,4 +79,10 @@ def main():
|
|
| 77 |
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
"""
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
+
import tempfile
|
| 9 |
|
| 10 |
|
| 11 |
def main():
|
|
|
|
| 36 |
print("2. Creating test video...")
|
| 37 |
from create_test_video import create_test_video
|
| 38 |
|
| 39 |
+
temp_dir = tempfile.gettempdir()
|
| 40 |
+
input_video = os.path.join(temp_dir, "quickstart_input.mp4")
|
| 41 |
+
output_video = os.path.join(temp_dir, "quickstart_output.mp4")
|
| 42 |
|
| 43 |
create_test_video(input_video, duration_sec=2, fps=15)
|
| 44 |
print()
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
+
try:
|
| 83 |
+
main()
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"\nβ Error: {e}")
|
| 86 |
+
import traceback
|
| 87 |
+
traceback.print_exc()
|
| 88 |
+
sys.exit(1)
|