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()