copilot-swe-agent[bot] kr4phy commited on
Commit
f4c30f7
Β·
1 Parent(s): 06417df

Fix cross-platform compatibility and add error handling

Browse files

Co-authored-by: kr4phy <168257476+kr4phy@users.noreply.github.com>

Files changed (3) hide show
  1. cli.py +26 -11
  2. create_sample_images.py +6 -4
  3. 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
- success = process_video(input_path, output_path)
31
-
32
- if success:
33
- print("\nβœ“ Video processing completed successfully!")
34
- print(f"βœ“ Result saved to: {output_path}")
35
 
36
- if os.path.exists(output_path):
37
- size = os.path.getsize(output_path)
38
- print(f"βœ“ File size: {size:,} bytes")
39
- else:
40
- print("\nβœ— Video processing failed!")
 
 
 
 
 
 
 
 
 
41
  sys.exit(1)
42
 
43
 
44
  if __name__ == "__main__":
45
- main()
 
 
 
 
 
 
 
 
 
 
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
- input_video = "/tmp/demo_input.mp4"
17
- output_video = "/tmp/demo_output.mp4"
 
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 = "/tmp/lane_detection_demo.png"
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 = "/tmp/lane_detection_demo_small.png"
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
- input_video = "/tmp/quickstart_input.mp4"
39
- output_video = "/tmp/quickstart_output.mp4"
 
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
- main()
 
 
 
 
 
 
 
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)