Spaces:
Sleeping
Sleeping
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()
|