Spaces:
Runtime error
Runtime error
copilot-swe-agent[bot] kr4phy commited on
Commit Β·
06417df
1
Parent(s): e40d5b1
Add CLI tool, quickstart script, and comprehensive documentation
Browse filesCo-authored-by: kr4phy <168257476+kr4phy@users.noreply.github.com>
- README.md +76 -7
- cli.py +45 -0
- create_sample_images.py +61 -0
- 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
3. **Canny μμ§ κ²μΆ** (Canny edge detection)
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
## μꡬμ¬ν (Requirements)
|
| 53 |
- Python 3.7+
|
| 54 |
-
- gradio=
|
| 55 |
-
- opencv-python=
|
| 56 |
-
- numpy=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|