Skip to content
Back to skills

Computer Vision

ASecurity

When to activate: computer vision, OpenCV, YOLO, YOLOv8, object detection, segmentation, albumentations, OCR, image classification

  • 2 stars
  • 0 votes
  • 3 copies
  • 11 views
  • Added October 26, 2026
ai-agentspythongo

Works with

  • cursor
  • cli

Security analysis

A100/100

Scanned October 26, 2026

npx -y skills add Mattakushi432/Claude-Code-Skills-Custom-DevTools-Pack --skill computer-vision --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Computer Vision?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Computer Vision
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattakushi432-computer-vision/badge)](https://www.skillsdirectory.com/skills/mattakushi432-computer-vision)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: computer-vision
description: "When to activate: computer vision, OpenCV, YOLO, YOLOv8, object detection, segmentation, albumentations, OCR, image classification"
origin: zakr
metadata:
  namespace: zakr/devtools-pack
  version: 1.0.0
  category: ml-ai
  language: python
  platforms: [claude-code, codex, gemini-cli, cursor, aider, windsurf]
---
# 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/val
test: images/test

nc: 3
names: ["cat", "dog", "bird"]
```

## Albumentations Augmentation Pipeline

```python
import albumentations as A
from albumentations.pytorch import ToTensorV2

train_transform = A.Compose([
    A.RandomResizedCrop(640, 640, scale=(0.5, 1.0)),
    A.HorizontalFlip(p=0.5),
    A.ColorJitter(brightness=0.2, contrast=0.2, saturation=0.2, hue=0.1, p=0.5),
    A.GaussNoise(var_limit=(10.0, 50.0), p=0.3),
    A.MotionBlur(blur_limit=5, p=0.2),
    A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    ToTensorV2(),
], bbox_params=A.BboxParams(format="yolo", label_fields=["class_labels"]))

val_transform = A.Compose([
    A.Resize(640, 640),
    A.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
    ToTensorV2(),
])
```

## Segmentation (SAM)

```python
from segment_anything import SamPredictor, sam_model_registry

sam = sam_model_registry["vit_h"](checkpoint="sam_vit_h.pth")
sam.to("cuda")
predictor = SamPredictor(sam)

predictor.set_image(img_rgb)
masks, scores, _ = predictor.predict(
    point_coords=np.array([[500, 375]]),
    point_labels=np.array([1]),   # 1=foreground
    multimask_output=True,
)
best_mask = masks[scores.argmax()]
```

## OCR with EasyOCR

```python
import easyocr

reader = easyocr.Reader(["en"], gpu=True)
results = reader.readtext("document.jpg")

for (bbox, text, confidence) in results:
    if confidence > 0.5:
        print(f"{text!r} ({confidence:.2f})")
```

## CLIP Zero-Shot Classification

```python
import torch
from PIL import Image
import open_clip

model, _, preprocess = open_clip.create_model_and_transforms("ViT-B-32", pretrained="openai")
tokenizer = open_clip.get_tokenizer("ViT-B-32")
model.eval()

image = preprocess(Image.open("photo.jpg")).unsqueeze(0)
labels = ["a cat", "a dog", "a bird"]
text = tokenizer(labels)

with torch.no_grad():
    img_feat = model.encode_image(image)
    txt_feat = model.encode_text(text)
    img_feat /= img_feat.norm(dim=-1, keepdim=True)
    txt_feat /= txt_feat.norm(dim=-1, keepdim=True)
    probs = (100 * img_feat @ txt_feat.T).softmax(dim=-1)

for label, prob in zip(labels, probs[0]):
    print(f"{label}: {prob:.2%}")
```

## Key Patterns

- Always normalize with ImageNet mean/std when using pretrained backbones
- Use `cv2.INTER_AREA` for downscaling, `cv2.INTER_LANCZOS4` for upscaling
- For detection fine-tuning: freeze backbone for first 10 epochs, then unfreeze
- Mosaic augmentation (YOLOv8 default) improves small object detection significantly

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.