computer-visionlisted
Install: claude install-skill Mattakushi432/Claude-Code-Skills-Custom-DevTools-Pack
# Computer Vision Patterns
## OpenCV Essentials
```python
import cv2
import numpy as np
img = cv2.imread("image.jpg") # BGR, not RGB
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Resize preserving aspect ratio
h, w = img.shape[:2]
scale = 640 / max(h, w)
resized = cv2.resize(img, (int(w * scale), int(h * scale)), interpolation=cv2.INTER_AREA)
# Gaussian blur + Canny edges
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edges = cv2.Canny(blurred, threshold1=50, threshold2=150)
# Draw bounding box
x, y, bw, bh = 100, 50, 200, 150
cv2.rectangle(img, (x, y), (x + bw, y + bh), color=(0, 255, 0), thickness=2)
cv2.putText(img, "Label 0.92", (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
```
## YOLOv8 Training & Inference
```python
from ultralytics import YOLO
# Training
model = YOLO("yolov8n.pt") # nano backbone
results = model.train(
data="dataset.yaml",
epochs=100,
imgsz=640,
batch=16,
device=0,
project="runs/detect",
name="exp1",
patience=20,
augment=True,
)
# Inference
model = YOLO("runs/detect/exp1/weights/best.pt")
results = model.predict("test.jpg", conf=0.4, iou=0.5, save=True)
for r in results:
for box in r.boxes:
cls = int(box.cls[0])
conf = float(box.conf[0])
xyxy = box.xyxy[0].tolist()
print(f"Class {cls} ({conf:.2f}): {xyxy}")
```
## YOLOv8 dataset.yaml
```yaml
path: /data/my_dataset
train: images/train
val: images/v