# Run2 Opencv Grayscale

> Convert images to grayscale in-place using OpenCV, including both keyframes and template images.

- Skill: `cxcscmu/run2-opencv-grayscale` (Agent Skill)
- Install (CLI): `npx get-skill add cxcscmu/run2-opencv-grayscale`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cxcscmu/run2-opencv-grayscale/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: cxcscmu (https://skillmd.com/u/cxcscmu)
- Updated: 2026-11-24
- Page: https://skillmd.com/skills/cxcscmu/run2-opencv-grayscale

---


# OpenCV Grayscale Conversion

## Convert All Images In-Place

Both keyframes AND template images must be converted to grayscale before template matching.

```python
import cv2
import glob

# Convert keyframes
for path in sorted(glob.glob('/root/keyframes_*.png')):
    img = cv2.imread(path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imwrite(path, gray)

# Convert templates
for path in ['/root/coin.png', '/root/enemy.png', '/root/turtle.png']:
    img = cv2.imread(path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imwrite(path, gray)
```

## Important

- The `count_objects.py` script reads with `IMREAD_GRAYSCALE`, so files must be grayscale before counting
- Overwriting originals is required per the task specification
- Grayscale images are single-channel (H x W) vs RGB (H x W x 3)

