์ปดํจํฐ ๋น์ ํ๋ก์ ํธ - ์ด๋ฏธ์ง ์ฒ๋ฆฌ, ์ ์ฒ๋ฆฌ, 2Dโ3D ๋ณํ ๋ฐ ๊ฐ์ฒด ํ์ง
comento_computer_vision/
โโโ README.md
โโโ week1_preprocessing/ # Week1: ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ฐ ์ ์ฒ๋ฆฌ
โ โโโ computer_vision_week1_base.py
โ โโโ computer_vision_week1_add.py
โ โโโ sample.jpg
โ โโโ preprocessed_samples/
โโโ week2_2d_to_3d/ # Week2: Unit Test ๋ฐ 2Dโ3D ๋ณํ
โ โโโ src/
โ โโโ tests/
โ โโโ scripts/
โ โโโ results/
โโโ week3_yolo/ # Week3: YOLOv8 ๊ฐ์ฒด ํ์ง
โโโ src/
โโโ results/
OpenCV์ Hugging Face ๋ฐ์ดํฐ์ ์ ํ์ฉํ ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ฐ ์ ์ฒ๋ฆฌ ์ค์ต ํ๋ก์ ํธ์ ๋๋ค.
- OpenCV๋ฅผ ์ฌ์ฉํ HSV ์์ ๊ณต๊ฐ ๊ธฐ๋ฐ ๋นจ๊ฐ์ ์์ญ ๊ฒ์ถ
- ๋ ๊ฐ์ ๋นจ๊ฐ์ ๋ฒ์๋ฅผ ์ค์ ํ์ฌ ์ ํํ ๊ฒ์ถ
- ๋ง์คํฌ ์์ฑ ๋ฐ ์๋ณธ ์ด๋ฏธ์ง์ ์ ์ฉ
- Hugging Face food101 ๋ฐ์ดํฐ์ ์ฌ์ฉ
- URL: https://huggingface.co/datasets/ethz/food101
- 5๊ฐ ์ํ ์ด๋ฏธ์ง๋ก ํ ์คํธ
- ๋๋ฌด ์ด๋์ด ์ด๋ฏธ์ง ํํฐ๋ง: ํ๊ท ๋ฐ๊ธฐ๊ฐ 50 ๋ฏธ๋ง์ธ ์ด๋ฏธ์ง ์ ๊ฑฐ
- ๊ฐ์ฒด ํฌ๊ธฐ ๊ฒ์ฆ: ํฝ์ ๋ถ์ฐ์ด 100 ๋ฏธ๋ง์ธ ์ด๋ฏธ์ง ์ ๊ฑฐ
- ํฌ๊ธฐ ์กฐ์ : ๋ชจ๋ ์ด๋ฏธ์ง๋ฅผ 224x224 ํฌ๊ธฐ๋ก ํต์ผ
- ์์ ๋ณํ: Grayscale ๋ณํ ๋ฐ 0-1 ์ฌ์ด๋ก ์ ๊ทํ
- ๋ ธ์ด์ฆ ์ ๊ฑฐ: Gaussian Blur ํํฐ ์ ์ฉ (radius=2)
- ๋ฐ์ดํฐ ์ฆ๊ฐ:
- ์ข์ฐ ๋ฐ์ (Horizontal Flip)
- 15๋ ํ์ (Rotation)
- ๋ฐ๊ธฐ ์กฐ์ (30% ์ฆ๊ฐ)
cd week1_preprocessing
pip install opencv-python numpy pillow datasets huggingface-hub
python computer_vision_week1_base.py
python computer_vision_week1_add.py์ ์ฒ๋ฆฌ๋ ์ด๋ฏธ์ง๋ preprocessed_samples/ ํด๋์ ์ ์ฅ๋ฉ๋๋ค:
food101_image_0_resized.jpg- ํฌ๊ธฐ ์กฐ์ food101_image_0_gray_normalized.jpg- Grayscale & ์ ๊ทํfood101_image_0_blurred.jpg- ๋ ธ์ด์ฆ ์ ๊ฑฐfood101_image_0_flipped.jpg- ์ข์ฐ ๋ฐ์ food101_image_0_rotated.jpg- ํ์ food101_image_0_brightened.jpg- ๋ฐ๊ธฐ ์กฐ์
(์ด 5๊ฐ ์ด๋ฏธ์ง ร 6๊ฐ ๋ณํ = 30๊ฐ ํ์ผ ์์ฑ)
AI ๊ธฐ๋ฐ ์ ํ ๊ฐ๋ฐ์ ์ํ Unit Test ๊ตฌ์ฑ ๋ฐ 2D โ 3D ๋ณํ ์ค์ต ํ๋ก์ ํธ์ ๋๋ค.
๋ณธ ํ๋ก์ ํธ๋ ๋ค์ ๋ชฉํ๋ฅผ ๋ฌ์ฑํฉ๋๋ค:
- Python์ pytest๋ฅผ ํ์ฉํ Unit Test ๊ตฌ์ฑ
- OpenCV์ NumPy๋ฅผ ์ฌ์ฉํ 2D โ 3D ๋ณํ ์๊ณ ๋ฆฌ์ฆ ๊ตฌํ
- ๊น์ด ๋งต(Depth Map) ์์ฑ ๋ฐ 3D ํฌ์ธํธ ํด๋ผ์ฐ๋ ๋ณํ
week2_2d_to_3d/
โโโ src/ # ์์ค ์ฝ๋
โ โโโ depth_3d_converter.py
โโโ tests/ # Unit Test
โ โโโ test_depth_3d_converter.py
โโโ scripts/ # ์คํ ์คํฌ๋ฆฝํธ
โ โโโ visualization_demo.py
โโโ results/ # ๊ฒฐ๊ณผ ์ด๋ฏธ์ง
โโโ comparison.png
โโโ shapes_pipeline.png
โโโ ...
2D ์ด๋ฏธ์ง์์ ๊น์ด ๋งต์ ์์ฑํฉ๋๋ค.
Parameters:
image: ์ ๋ ฅ ์ด๋ฏธ์ง (BGR ํ์ ๋๋ ๊ทธ๋ ์ด์ค์ผ์ผ)method: ๊น์ด ์ถ์ ๋ฐฉ๋ฒ"gradient": Sobel ๊ธฐ๋ฐ ๊ธฐ์ธ๊ธฐ ์ถ์ "intensity": ๋ฐ๊ธฐ ๊ธฐ๋ฐ ์ถ์ "edge": Canny ์ฃ์ง ๊ธฐ๋ฐ ์ถ์
Returns:
depth_map: ๊น์ด ๋งต (uint8, grayscale)
๊น์ด ๋งต์ ์ปฌ๋ฌ๋งต์ ์ ์ฉํ์ฌ ์๊ฐํํฉ๋๋ค.
๊น์ด ๋งต์ 3D ํฌ์ธํธ ํด๋ผ์ฐ๋๋ก ๋ณํํฉ๋๋ค.
3D ํฌ์ธํธ ํด๋ผ์ฐ๋๋ฅผ PLY ํ์ผ๋ก ์ ์ฅํฉ๋๋ค.
์ ์ฒด 2D โ 3D ๋ณํ ํ์ดํ๋ผ์ธ์ ์คํํฉ๋๋ค.
| ํด๋์ค | ํ ์คํธ ํญ๋ชฉ |
|---|---|
TestGenerateDepthMap |
๊น์ด ๋งต ์์ฑ ๊ธฐ๋ฅ, ์ ๋ ฅ ๊ฒ์ฆ, ๋ค์ํ ๋ฐฉ๋ฒ ํ ์คํธ |
TestApplyColormap |
์ปฌ๋ฌ๋งต ์ ์ฉ, ์ถ๋ ฅ ํ์ ๊ฒ์ฆ |
TestConvertTo3DPoints |
3D ํฌ์ธํธ ๋ณํ, ํ๋ผ๋ฏธํฐ ๊ฒ์ฆ |
TestSavePointCloudPLY |
PLY ํ์ผ ์ ์ฅ, ํ์ ๊ฒ์ฆ |
TestProcess2DTo3D |
ํตํฉ ํ์ดํ๋ผ์ธ ํ ์คํธ |
TestEdgeCases |
๊ฒฝ๊ณ ์กฐ๊ฑด ๋ฐ ์ฃ์ง ์ผ์ด์ค |
========================= test session starts ==========================
collected 43 items
test_depth_3d_converter.py::TestGenerateDepthMap::test_basic_functionality PASSED
test_depth_3d_converter.py::TestGenerateDepthMap::test_output_shape PASSED
...
========================= 43 passed in 0.92s ===========================
cd week2_2d_to_3d
pip install numpy opencv-python pytest matplotlib
# Unit Test ์คํ
pytest tests/test_depth_3d_converter.py -v
# ์์ธ ์ถ๋ ฅ
pytest tests/test_depth_3d_converter.py -v --tb=short
# ์๊ฐํ ๋ฐ๋ชจ ์คํ
python scripts/visualization_demo.pyfrom src.depth_3d_converter import process_2d_to_3d
result = process_2d_to_3d("your_image.jpg", "./output")
print(f"3D ํฌ์ธํธ ์: {result['num_3d_points']}")- ๊น์ด ๋งต ์ด๋ฏธ์ง (
*_depth.png) - ๊ทธ๋ ์ด์ค์ผ์ผ ๊น์ด ์ ๋ณด - ์ปฌ๋ฌ ๊น์ด ๋งต (
*_depth_colored.png) - JET ์ปฌ๋ฌ๋งต ์ ์ฉ ์๊ฐํ - 3D ํฌ์ธํธ ํด๋ผ์ฐ๋ (
*_points.ply) - MeshLab, CloudCompare ๋ฑ์์ ํ์ธ ๊ฐ๋ฅ - ํ์ดํ๋ผ์ธ ๋น๊ต ์ด๋ฏธ์ง (
*_pipeline.png) - ์๋ณธ โ ๊น์ด ๋งต โ 3D ๋ณํ ๊ณผ์
YOLOv8์ ํ์ฉํ ๊ฐ์ฒด ํ์ง ๋ชจ๋ธ ํ์ต ๋ฐ OpenCV๋ฅผ ํตํ ๊ฒฐ๊ณผ ์๊ฐํ ํ๋ก์ ํธ์ ๋๋ค.
๋ณธ ํ๋ก์ ํธ๋ ๋ค์ ๋ชฉํ๋ฅผ ๋ฌ์ฑํฉ๋๋ค:
- YOLOv8 ๋ชจ๋ธ์ ํ์ฉํ ์ปค์คํ ๋ฐ์ดํฐ์ ํ์ต
- OpenCV๋ฅผ ์ฌ์ฉํ ๊ฐ์ฒด ํ์ง ๊ฒฐ๊ณผ ์๊ฐํ
- Matplotlib์ ํ์ฉํ ๋ชจ๋ธ ์ฑ๋ฅ ํ๊ฐ ์๊ฐํ
week3_yolo/
โโโ src/
โ โโโ data.yaml # ๋ฐ์ดํฐ์
์ค์ ํ์ผ
โ โโโ train.py # ๋ชจ๋ธ ํ์ต ์คํฌ๋ฆฝํธ
โ โโโ detect.py # ๊ฐ์ฒด ํ์ง + OpenCV ์๊ฐํ
โ โโโ visualize.py # ์ฑ๋ฅ ๊ทธ๋ํ ์๊ฐํ
โโโ results/
โ โโโ detection_result.jpg # ํ์ง ๊ฒฐ๊ณผ ์ด๋ฏธ์ง
โ โโโ model_performance.png # Precision/Recall ๊ทธ๋ํ
โโโ datasets/
โโโ train/{images, labels}
โโโ valid/{images, labels}
โโโ test/{images, labels}
train: ./datasets/train/images
val: ./datasets/valid/images
nc: 3
names: ['person', 'car', 'dog']YOLO ๋ผ๋ฒจ ํ์ (txt ํ์ผ):
# class_id x_center y_center width height (0~1 ์ ๊ทํ)
0 0.5 0.5 0.3 0.4
1 0.2 0.3 0.1 0.2
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # YOLOv8 ๊ธฐ๋ณธ ๋ชจ๋ธ
model.train(data="data.yaml", epochs=10, imgsz=640)ํ์ต ํ๋ผ๋ฏธํฐ:
- Epochs: 10 (๊ธฐ๋ณธ) / 20 (์ฆ๊ฐ ์ ์ฉ ์)
- Image Size: 640x640
- Model: YOLOv8n (nano)
import cv2
from ultralytics import YOLO
model = YOLO("runs/train/exp/weights/best.pt")
results = model(image)
for result in results:
for box in result.boxes:
x1, y1, x2, y2 = map(int, box.xyxy[0])
label = result.names[int(box.cls[0])]
confidence = box.conf[0]
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(image, f"{label} {confidence:.2f}", (x1, y1-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)import matplotlib.pyplot as plt
metrics = model.val()
plt.plot(metrics['precision'], label="Precision")
plt.plot(metrics['recall'], label="Recall")
plt.xlabel("Epochs")
plt.ylabel("Score")
plt.legend()
plt.title("Model Performance")
plt.savefig("../results/model_performance.png")cd week3_yolo/src
pip install torch torchvision opencv-python matplotlib ultralytics
# ๋ชจ๋ธ ํ์ต
python train.py
# ๊ฐ์ฒด ํ์ง
python detect.py
# ๊ฒฐ๊ณผ ์๊ฐํ
python visualize.py| ๋ฉํธ๋ฆญ | ์ค๋ช |
|---|---|
| mAP@0.5 | IoU 0.5 ๊ธฐ์ค ํ๊ท ์ ๋ฐ๋ |
| mAP@0.5:0.95 | IoU 0.5~0.95 ๊ธฐ์ค ํ๊ท ์ ๋ฐ๋ |
| Precision | ํ์งํ ๊ฐ์ฒด ์ค ์ ๋ต ๋น์จ |
| Recall | ์ค์ ๊ฐ์ฒด ์ค ํ์งํ ๋น์จ |
- detection_result.jpg - ๋ฐ์ด๋ฉ ๋ฐ์ค๊ฐ ํ์๋ ํ์ง ๊ฒฐ๊ณผ
- model_performance.png - Precision/Recall ํ์ต ๊ณก์
-
๋ฐ์ดํฐ ์ฆ๊ฐ (Augmentation)
- ์ด๋ฏธ์ง ํ์ , ๋ฐ๊ธฐ ์กฐ์ , ๋ ธ์ด์ฆ ์ถ๊ฐ
model.train(data="data.yaml", epochs=20, imgsz=640, augment=True)
-
ํ์ดํผํ๋ผ๋ฏธํฐ ํ๋
- ํ์ต๋ฅ ์กฐ์
- Batch Size ์กฐ์
-
๋ ํฐ ๋ชจ๋ธ ์ฌ์ฉ
yolov8s.pt(small)yolov8m.pt(medium)yolov8l.pt(large)