copilot-swe-agent[bot] kr4phy commited on
Commit
06417df
ยท
1 Parent(s): e40d5b1

Add CLI tool, quickstart script, and comprehensive documentation

Browse files

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

Files changed (4) hide show
  1. README.md +76 -7
  2. cli.py +45 -0
  3. create_sample_images.py +61 -0
  4. quickstart.py +80 -0
README.md CHANGED
@@ -10,6 +10,8 @@ This project is a demo application that detects lane lines in videos using OpenC
10
  - ๐ŸŽฅ Gradio๋ฅผ ํ†ตํ•œ ๋น„๋””์˜ค ์—…๋กœ๋“œ (Video upload via Gradio)
11
  - ๐Ÿ›ฃ๏ธ OpenCV๋ฅผ ์ด์šฉํ•œ ์‹ค์‹œ๊ฐ„ ์ฐจ์„  ๊ฒ€์ถœ (Real-time lane detection using OpenCV)
12
  - ๐Ÿ“Š ์›๋ณธ/์ฒ˜๋ฆฌ ๋น„๋””์˜ค ์‚ฌ์ด๋“œ๋ฐ”์ด์‚ฌ์ด๋“œ ๋น„๊ต (Side-by-side comparison of original and processed videos)
 
 
13
 
14
  ## ์„ค์น˜ (Installation)
15
 
@@ -26,6 +28,8 @@ pip install -r requirements.txt
26
 
27
  ## ์‚ฌ์šฉ๋ฒ• (Usage)
28
 
 
 
29
  1. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ (Run the application):
30
  ```bash
31
  python app.py
@@ -40,20 +44,85 @@ python app.py
40
  4. ์ฒ˜๋ฆฌ๋œ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค (์™ผ์ชฝ: ์›๋ณธ, ์˜ค๋ฅธ์ชฝ: ์ฐจ์„  ๊ฐ์ง€ ๊ฒฐ๊ณผ).
41
  (View the processed result - left: original, right: lane detection result)
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ## ์ฐจ์„  ๊ฐ์ง€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (Lane Detection Algorithm)
44
 
 
 
 
45
  1. **Grayscale ๋ณ€ํ™˜** (Convert to grayscale)
46
- 2. **๊ฐ€์šฐ์‹œ์•ˆ ๋ธ”๋Ÿฌ** ์ ์šฉ (Apply Gaussian blur)
 
 
 
 
47
  3. **Canny ์—์ง€ ๊ฒ€์ถœ** (Canny edge detection)
48
- 4. **๊ด€์‹ฌ ์˜์—ญ(ROI) ๋งˆ์Šคํ‚น** (Apply region of interest mask)
49
- 5. **Hough ๋ณ€ํ™˜**์œผ๋กœ ์ง์„  ๊ฒ€์ถœ (Detect lines using Hough transform)
50
- 6. **์ฐจ์„  ํ‰๊ท ํ™” ๋ฐ ๊ทธ๋ฆฌ๊ธฐ** (Average and draw lane lines)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  ## ์š”๊ตฌ์‚ฌํ•ญ (Requirements)
53
  - Python 3.7+
54
- - gradio==4.44.0
55
- - opencv-python==4.10.0.84
56
- - numpy==1.26.4
 
 
 
 
 
57
 
58
  ## ๋ผ์ด์„ ์Šค (License)
59
  MIT License
 
 
 
 
 
 
 
 
 
10
  - ๐ŸŽฅ Gradio๋ฅผ ํ†ตํ•œ ๋น„๋””์˜ค ์—…๋กœ๋“œ (Video upload via Gradio)
11
  - ๐Ÿ›ฃ๏ธ OpenCV๋ฅผ ์ด์šฉํ•œ ์‹ค์‹œ๊ฐ„ ์ฐจ์„  ๊ฒ€์ถœ (Real-time lane detection using OpenCV)
12
  - ๐Ÿ“Š ์›๋ณธ/์ฒ˜๋ฆฌ ๋น„๋””์˜ค ์‚ฌ์ด๋“œ๋ฐ”์ด์‚ฌ์ด๋“œ ๋น„๊ต (Side-by-side comparison of original and processed videos)
13
+ - ๐Ÿ’ป CLI ๋„๊ตฌ ์ œ๊ณต (Command-line interface available)
14
+ - ๐Ÿงช ํฌ๊ด„์ ์ธ ํ…Œ์ŠคํŠธ ์Šค์œ„ํŠธ (Comprehensive test suite)
15
 
16
  ## ์„ค์น˜ (Installation)
17
 
 
28
 
29
  ## ์‚ฌ์šฉ๋ฒ• (Usage)
30
 
31
+ ### ๋ฐฉ๋ฒ• 1: Gradio UI ์‚ฌ์šฉ (Using Gradio UI)
32
+
33
  1. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ (Run the application):
34
  ```bash
35
  python app.py
 
44
  4. ์ฒ˜๋ฆฌ๋œ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค (์™ผ์ชฝ: ์›๋ณธ, ์˜ค๋ฅธ์ชฝ: ์ฐจ์„  ๊ฐ์ง€ ๊ฒฐ๊ณผ).
45
  (View the processed result - left: original, right: lane detection result)
46
 
47
+ ### ๋ฐฉ๋ฒ• 2: CLI ์‚ฌ์šฉ (Using Command Line)
48
+
49
+ ```bash
50
+ python cli.py input_video.mp4 output_video.mp4
51
+ ```
52
+
53
+ ์˜ˆ์‹œ (Example):
54
+ ```bash
55
+ # ํ…Œ์ŠคํŠธ ๋น„๋””์˜ค ์ƒ์„ฑ (Create test video)
56
+ python create_test_video.py
57
+
58
+ # ์ฐจ์„  ๊ฐ์ง€ ์ฒ˜๋ฆฌ (Process with lane detection)
59
+ python cli.py /tmp/test_road_video.mp4 result.mp4
60
+ ```
61
+
62
  ## ์ฐจ์„  ๊ฐ์ง€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (Lane Detection Algorithm)
63
 
64
+ ๋ณธ ํ”„๋กœ์ ํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ปดํ“จํ„ฐ ๋น„์ „ ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค:
65
+ (This project uses the following computer vision techniques:)
66
+
67
  1. **Grayscale ๋ณ€ํ™˜** (Convert to grayscale)
68
+ - ์ปฌ๋Ÿฌ ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์ฒ˜๋ฆฌ ์†๋„ ํ–ฅ์ƒ
69
+
70
+ 2. **๊ฐ€์šฐ์‹œ์•ˆ ๋ธ”๋Ÿฌ** (Gaussian blur)
71
+ - ๋…ธ์ด์ฆˆ ์ œ๊ฑฐ ๋ฐ ์—์ง€ ๊ฒ€์ถœ ์„ฑ๋Šฅ ํ–ฅ์ƒ
72
+
73
  3. **Canny ์—์ง€ ๊ฒ€์ถœ** (Canny edge detection)
74
+ - ์ด๋ฏธ์ง€์—์„œ ๊ฐ€์žฅ์ž๋ฆฌ(edge) ๊ฒ€์ถœ
75
+
76
+ 4. **๊ด€์‹ฌ ์˜์—ญ(ROI) ๋งˆ์Šคํ‚น** (Region of Interest masking)
77
+ - ๋„๋กœ ์˜์—ญ์—๋งŒ ์ง‘์ค‘ํ•˜์—ฌ ๋ถˆํ•„์š”ํ•œ ์˜์—ญ ์ œ์™ธ
78
+
79
+ 5. **Hough ๋ณ€ํ™˜** (Hough transform)
80
+ - ์ง์„  ํ˜•ํƒœ์˜ ์ฐจ์„  ๊ฒ€์ถœ
81
+
82
+ 6. **์ฐจ์„  ํ‰๊ท ํ™” ๋ฐ ๊ทธ๋ฆฌ๊ธฐ** (Lane averaging and drawing)
83
+ - ๊ฒ€์ถœ๋œ ์—ฌ๋Ÿฌ ์„ ๋ถ„์„ ํ‰๊ท ํ™”ํ•˜์—ฌ ์•ˆ์ •์ ์ธ ์ฐจ์„  ํ‘œ์‹œ
84
+
85
+ ## ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ (Project Structure)
86
+
87
+ ```
88
+ OpenCVLaneDetectionDemo/
89
+ โ”œโ”€โ”€ app.py # Gradio UI ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜
90
+ โ”œโ”€โ”€ lane_detection.py # ํ•ต์‹ฌ ์ฐจ์„  ๊ฒ€์ถœ ๋กœ์ง
91
+ โ”œโ”€โ”€ cli.py # ๋ช…๋ น์ค„ ์ธํ„ฐํŽ˜์ด์Šค
92
+ โ”œโ”€โ”€ create_test_video.py # ํ…Œ์ŠคํŠธ ๋น„๋””์˜ค ์ƒ์„ฑ ๋„๊ตฌ
93
+ โ”œโ”€โ”€ create_sample_images.py # ์ƒ˜ํ”Œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋„๊ตฌ
94
+ โ”œโ”€โ”€ test_lane_detection.py # ํ…Œ์ŠคํŠธ ์Šค์œ„ํŠธ
95
+ โ”œโ”€โ”€ requirements.txt # Python ์˜์กด์„ฑ
96
+ โ””โ”€โ”€ README.md # ๋ฌธ์„œ
97
+ ```
98
+
99
+ ## ํ…Œ์ŠคํŠธ (Testing)
100
+
101
+ ์ „์ฒด ํ…Œ์ŠคํŠธ ์Šค์œ„ํŠธ ์‹คํ–‰:
102
+ (Run the complete test suite:)
103
+
104
+ ```bash
105
+ python test_lane_detection.py
106
+ ```
107
 
108
  ## ์š”๊ตฌ์‚ฌํ•ญ (Requirements)
109
  - Python 3.7+
110
+ - gradio>=4.0.0
111
+ - opencv-python>=4.5.0
112
+ - numpy>=1.20.0
113
+
114
+ ## ๊ธฐ์ˆ  ์Šคํƒ (Tech Stack)
115
+ - **OpenCV**: ์ปดํ“จํ„ฐ ๋น„์ „ ์ฒ˜๋ฆฌ
116
+ - **NumPy**: ์ˆ˜์น˜ ์—ฐ์‚ฐ
117
+ - **Gradio**: ์›น UI ํ”„๋ ˆ์ž„์›Œํฌ
118
 
119
  ## ๋ผ์ด์„ ์Šค (License)
120
  MIT License
121
+
122
+ ## ๊ธฐ์—ฌ (Contributing)
123
+ ์ด์Šˆ์™€ ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!
124
+ (Issues and pull requests are welcome!)
125
+
126
+ ## ๋ฌธ์˜ (Contact)
127
+ ํ”„๋กœ์ ํŠธ์— ๋Œ€ํ•œ ์งˆ๋ฌธ์ด๋‚˜ ์ œ์•ˆ์‚ฌํ•ญ์ด ์žˆ์œผ์‹œ๋ฉด ์ด์Šˆ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์„ธ์š”.
128
+ (For questions or suggestions about the project, please create an issue.)
cli.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command-line interface for lane detection
4
+ Usage: python cli.py <input_video> <output_video>
5
+ """
6
+ import sys
7
+ import os
8
+ from lane_detection import process_video
9
+
10
+
11
+ def main():
12
+ if len(sys.argv) != 3:
13
+ print("Usage: python cli.py <input_video> <output_video>")
14
+ print("\nExample:")
15
+ print(" python cli.py road_video.mp4 output_result.mp4")
16
+ sys.exit(1)
17
+
18
+ input_path = sys.argv[1]
19
+ output_path = sys.argv[2]
20
+
21
+ # Check if input file exists
22
+ if not os.path.exists(input_path):
23
+ print(f"Error: Input file '{input_path}' not found!")
24
+ sys.exit(1)
25
+
26
+ print(f"Processing video: {input_path}")
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()
create_sample_images.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Create sample images to demonstrate lane detection
3
+ """
4
+ import cv2
5
+ import numpy as np
6
+ import os
7
+
8
+
9
+ def create_sample_frames():
10
+ """Create and save sample frames showing lane detection"""
11
+
12
+ # First, create a test video and process it
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...")
21
+ create_test_video(input_video, duration_sec=2, fps=15)
22
+
23
+ print("Processing video with lane detection...")
24
+ success = process_video(input_video, output_video)
25
+
26
+ if not success:
27
+ print("Failed to process video")
28
+ return
29
+
30
+ # Extract a sample frame from the output
31
+ cap = cv2.VideoCapture(output_video)
32
+
33
+ # Get a frame from the middle of the video
34
+ total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
35
+ middle_frame = total_frames // 2
36
+
37
+ cap.set(cv2.CAP_PROP_POS_FRAMES, middle_frame)
38
+ ret, frame = cap.read()
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)")
46
+
47
+ # Also create a smaller version for documentation
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:
55
+ print("Failed to extract frame")
56
+
57
+ cap.release()
58
+
59
+
60
+ if __name__ == "__main__":
61
+ create_sample_frames()
quickstart.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Quick start script to test the lane detection system
4
+ Creates a test video, processes it, and verifies the output
5
+ """
6
+ import os
7
+ import sys
8
+
9
+
10
+ def main():
11
+ print("=" * 60)
12
+ print("OpenCV Lane Detection Demo - Quick Start")
13
+ print("=" * 60)
14
+ print()
15
+
16
+ # Check imports
17
+ print("1. Checking dependencies...")
18
+ try:
19
+ import cv2
20
+ print(f" โœ“ OpenCV {cv2.__version__}")
21
+ except ImportError:
22
+ print(" โœ— OpenCV not found. Run: pip install opencv-python")
23
+ sys.exit(1)
24
+
25
+ try:
26
+ import numpy as np
27
+ print(f" โœ“ NumPy {np.__version__}")
28
+ except ImportError:
29
+ print(" โœ— NumPy not found. Run: pip install numpy")
30
+ sys.exit(1)
31
+
32
+ print()
33
+
34
+ # Create test video
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()
43
+
44
+ # Process video
45
+ print("3. Processing video with lane detection...")
46
+ from lane_detection import process_video
47
+
48
+ success = process_video(input_video, output_video)
49
+
50
+ if not success:
51
+ print(" โœ— Processing failed!")
52
+ sys.exit(1)
53
+
54
+ print(f" โœ“ Processing complete!")
55
+ print()
56
+
57
+ # Verify output
58
+ print("4. Verifying output...")
59
+ if os.path.exists(output_video):
60
+ size = os.path.getsize(output_video)
61
+ print(f" โœ“ Output file created: {output_video}")
62
+ print(f" โœ“ File size: {size:,} bytes")
63
+ else:
64
+ print(" โœ— Output file not found!")
65
+ sys.exit(1)
66
+
67
+ print()
68
+ print("=" * 60)
69
+ print("โœ… SUCCESS! Lane detection system is working correctly.")
70
+ print("=" * 60)
71
+ print()
72
+ print("Next steps:")
73
+ print(" โ€ข Run Gradio UI: python app.py")
74
+ print(" โ€ข Use CLI tool: python cli.py <input> <output>")
75
+ print(" โ€ข Run tests: python test_lane_detection.py")
76
+ print()
77
+
78
+
79
+ if __name__ == "__main__":
80
+ main()