/media-os:cv-opencv [action]from media-os
Computer vision on images and video via OpenCV 4.x: face detection, object tracking, YOLO inference, camera calibration, panorama stitching, optical flow, and dnn model loading.
Ships in media-os. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Context: $ARGUMENTS
OpenCV 4.x via the Python cv2 binding. Python is the first-class surface — the C++, Java (javadoc), and JS (opencv.js) APIs are parallel and the same concepts port over. Canonical docs: https://docs.opencv.org/4.x/.
cv.py info)cv.py capture)cv.py detect-faces)cv.py track)cv.py yolo)cv.py calibrate)cv.py stitch)cv2.dnn is the lightweight path.cv2.VideoCapture / cv2.VideoWriter).cv-mediapipe skill instead — it's a different ecosystem with its own Tasks API.Three PyPI wheels, mutually exclusive — picking the wrong one hides features or wastes install.
| Wheel | Includes | Use when |
|---|---|---|
opencv-python | main repo only | basic imgproc/videoio/dnn |
opencv-contrib-python | main + contrib (ximgproc, tracking, aruco) | recommended default |
opencv-python-headless | main, no GUI (no imshow) | servers / Docker |
opencv-contrib-python-headless | contrib, no GUI | headless + contrib modules |
Install exactly one:
pip install opencv-contrib-python
# or via uv: uv pip install opencv-contrib-python
Never install both opencv-python and opencv-contrib-python — they conflict on cv2/*.so.
The helper scripts/cv.py declares opencv-contrib-python via PEP 723 so uv run handles it in an ephemeral venv.
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py info path/to/image.png
Prints: shape (H, W, C), dtype (uint8 / uint16 / float32), channel count, min/max/mean per channel, and whether the file is readable by cv2.imread. If cv2.imread returns None, the file is either unreadable, the wrong format, or a non-ASCII path on Windows (use cv2.imdecode + np.fromfile in that case).
OpenCV's default channel order is BGR, not RGB. All operations assume BGR. Convert to RGB explicitly before handing to matplotlib / PIL / torchvision:
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# webcam 0, 30 frames
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py capture --src 0 --count 30 --out frames/
# RTSP stream
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py capture --src 'rtsp://host/stream' --count 60 --out frames/
# video file
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py capture --src in.mp4 --count 100 --out frames/
VideoCapture uses the first backend that accepts the URL. Force a backend with cv2.VideoCapture(src, cv2.CAP_FFMPEG | cv2.CAP_GSTREAMER | cv2.CAP_AVFOUNDATION | cv2.CAP_V4L2 | cv2.CAP_MSMF).
On macOS, webcam access requires Terminal to hold the camera permission (System Settings → Privacy & Security → Camera). On Linux, /dev/video0 must exist and be readable by your user.
Do NOT use Haar cascades for new work. cv2.FaceDetectorYN (YuNet) is the current recommendation — small (<1 MB), fast, accurate, works on any CPU.
# downloads model if not present in models/
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py detect-faces path/to/image.jpg \
--model models/face_detection_yunet_2023mar.onnx \
--score-threshold 0.9
Download the YuNet ONNX from https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet. Outputs per-face bbox + 5 landmarks (eyes, nose, mouth corners).
For face recognition, pair with cv2.FaceRecognizerSF (SFace) — 512-d embeddings, cosine-distance matching.
The tracker API in 4.x moved out of cv2.legacy for the modern trackers:
| Tracker | Modern API (cv2.Tracker*_create) | Legacy (cv2.legacy.Tracker*_create) | Notes |
|---|---|---|---|
| MIL | yes | yes | slow, still accurate |
| KCF | yes | yes | fast, CSRT is better |
| CSRT | yes | yes | best classical default |
| GOTURN | yes | no | needs .caffemodel + .prototxt |
| Nano | yes | no | modern NN tracker, ONNX backend |
| Vit | yes | no | Vision Transformer tracker |
| DaSiamRPN | yes | no | Siamese RPN, ONNX backend |
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py track --src video.mp4 \
--bbox "x,y,w,h" --tracker csrt --out tracked.mp4
Pick the bbox on the first frame; the script writes an annotated video.
Readers (in order of popularity):
cv2.dnn.readNetFromONNX(model.onnx) — most moderncv2.dnn.readNetFromTensorflow(frozen.pb, graph.pbtxt)cv2.dnn.readNetFromCaffe(deploy.prototxt, weights.caffemodel)cv2.dnn.readNetFromDarknet(cfg, weights) — YOLOv3/v4cv2.dnn.readNetFromTorch(model.t7) — legacy Torchcv2.dnn.readNet(path) — auto-detect by extensionSet backend + target AFTER loading:
net = cv2.dnn.readNetFromONNX("yolov8n.onnx")
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV) # or CUDA / INFERENCE_ENGINE / VKCOM
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU) # or OPENCL / OPENCL_FP16 / CUDA / CUDA_FP16 / MYRIAD
Full backend × target compatibility matrix in references/dnn-backends.md.
Typical YOLO call (ONNX, letterbox-resize, NMS):
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py yolo \
--model yolov8n.onnx \
--input image.jpg \
--conf 0.25 --iou 0.45 \
--labels coco.names
The script uses cv2.dnn.blobFromImage + net.forward() + cv2.dnn.NMSBoxes.
Real OpenCV Python sample apps (upstream samples/dnn/) cover classification, detection, segmentation, openpose, text detection, face detect — they are the best reference for wiring new models.
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py calibrate \
--pattern chessboard --size 9x6 --square-mm 25 \
--images 'calib/*.jpg' --out camera.yaml
Writes intrinsic matrix K, distortion coefficients, RMS reprojection error. 15+ images from different angles are recommended for a solid fit. For ArUco / ChArUco boards, use cv2.aruco.CharucoBoard + cv2.aruco.detectMarkers — better than chessboard at extreme angles.
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py stitch pano1.jpg pano2.jpg pano3.jpg --out pano.jpg
Uses cv2.Stitcher.create(). Modes: cv2.Stitcher.PANORAMA (default) or cv2.Stitcher.SCANS (flat docs). If it returns ERR_NEED_MORE_IMGS / ERR_HOMOGRAPHY_EST_FAIL, the overlap between input images is insufficient or feature matches are too sparse — feed more overlapping shots.
Real binaries (install via your distro or from source with cmake --build . --target install):
opencv_version — prints 4.x.y. Sanity check.opencv_interactive-calibration — guided camera calibration (replaces the old calibrator).opencv_visualisation — single-sample visualiser for cascade classifiers.opencv_model_diagnostics — dnn model inspector.opencv_perf_*, opencv_test_* — only present when built with BUILD_TESTS=ON / BUILD_PERF_TESTS=ON.Gotcha: opencv_traincascade and opencv_annotation were removed in OpenCV 4.x. They exist only on the 3.4 branch. If you need to train a new cascade, either use the 3.4 binary or retarget to modern DNN workflows (YOLO / SSD / YuNet).
imread output is BGR. cv2.imshow expects BGR. Convert explicitly for RGB consumers.cv2.imread returns None silently on unreadable paths. Always check if img is None: after load.cv2.imdecode(np.fromfile(path, np.uint8), cv2.IMREAD_COLOR) rather than cv2.imread.cv2.TrackerCSRT_create(), not cv2.legacy.TrackerCSRT_create(), unless you explicitly need the old API.cv2.dnn blobFromImage ordering matters — for most ONNX models you want swapRB=True (BGR→RGB) and scalefactor=1/255.0. Check the model card.minDist, param1, param2 are extremely sensitive. Pre-blur (cv2.GaussianBlur(img, (9,9), 2)) before calling.mp4v writes a non-standard MP4; use avc1 for H.264 (requires FFmpeg backend). MJPG always works but bloats files.(x, y) in most APIs but (row, col) == (y, x) when indexing numpy arrays. The canonical bug.cv2.findContours signature changed between OpenCV 3 → 4. In 4.x: contours, hierarchy = cv2.findContours(...) (2 returns). 3.x returned 3. Never unpack 3 in 4.x code.setInputSize before detect (or it throws cryptic size errors). Pass (w, h) of the actual image.DNN_TARGET_CUDA is required.opencv_traincascade is not in 4.x — see the note above.cv2.CascadeClassifier) but produce many false positives vs YuNet. Use YuNet for any new face-detection work.cv2.aruco is now bundled in opencv-python (no contrib needed). Older guides say contrib; check your version with cv2.__version__.uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py detect-faces photo.jpg \
--model models/face_detection_yunet_2023mar.onnx \
--out photo_faces.jpg --draw
Download the model once:
curl -L -o models/face_detection_yunet_2023mar.onnx \
'https://github.com/opencv/opencv_zoo/raw/main/models/face_detection_yunet/face_detection_yunet_2023mar.onnx'
# manually pick the bbox on frame 0 (x,y,w,h)
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py track --src dashcam.mp4 \
--bbox "640,360,120,80" --tracker csrt --out tracked.mp4
Export from ultralytics first: yolo export model=yolov8n.pt format=onnx. Then:
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py yolo \
--model yolov8n.onnx --input street.jpg \
--labels coco.names --out street_det.jpg --conf 0.3
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py calibrate \
--pattern chessboard --size 9x6 --square-mm 25 \
--images 'calib/IMG_*.jpg' --out camera.yaml
The YAML contains camera_matrix, dist_coeff, rms. Load with cv2.FileStorage.
uv run ${CLAUDE_SKILL_DIR}/scripts/cv.py stitch shot1.jpg shot2.jpg shot3.jpg shot4.jpg --out pano.jpg
cv2.error: (-215:Assertion failed) !_src.empty()Cause: imread returned None — the file path is wrong, unreadable, or non-ASCII on Windows.
Solution: Check os.path.exists(path) first; on Windows use cv2.imdecode(np.fromfile(path, np.uint8), cv2.IMREAD_COLOR).
AttributeError: module 'cv2' has no attribute 'FaceDetectorYN'Cause: OpenCV < 4.5.4, or the module failed to compile.
Solution: pip install -U opencv-contrib-python. Verify cv2.__version__ is >= 4.8.
cv2.error: OpenCV(4.x) ... cv::dnn::readNetFromONNX_ ... can't open fileCause: model path wrong or file corrupted during download.
Solution: check file size vs upstream; re-download via curl -L.
TrackerCSRT_create exists but track() returns false every frameCause: initial bbox empty or off-screen.
Solution: verify (x, y, w, h) are inside the first frame and w > 0 and h > 0.
Cause: OS-level camera permission not granted; wrong camera index; another app holds it. Solution: On macOS grant Terminal/iTerm Camera permission; try indices 0, 1, 2; close Zoom / FaceTime / OBS.
opencv_traincascade: command not foundCause: Tool removed in 4.x. Solution: Use OpenCV 3.4 branch explicitly for cascade training, or move to modern DNN detectors (YuNet, YOLO, SSD).
references/modules.md when you need a one-line description of every OpenCV module group (core, imgproc, imgcodecs, videoio, calib3d, features2d, objdetect, dnn, ml, photo, stitching, video, ximgproc…) plus the canonical URL for each.references/dnn-backends.md when choosing a cv2.dnn backend × target combination, especially for GPU / OpenVINO / Vulkan deployment.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub damionrashford/media-os --plugin media-os110 skills in this plugin
/audio-coreaudioManipulate macOS audio at the Core Audio HAL layer: afinfo (audio file metadata), afplay (play), afconvert (convert format/rate/bit-depth/channel layout), say (TTS), SwitchAudioSource (change default input/output/system device — brew install switchaudio-osx), audiodevice CLIs (npm/Go variants), AppleScript via osascript to drive System Preferences Sound. HAL plugins at /Library/Audio/Plug-Ins/HAL/ load virtual drivers (BlackHole 2ch/16ch/64ch, Loopback, Background Music). Aggregate Device (drift-corrected multi-in) and Multi-Output Device via Audio MIDI Setup.app or AudioHardwareCreateAggregateDevice. Use when the user asks to change default macOS audio device, route audio between apps on Mac, install BlackHole, build an Aggregate Device, convert audio files with afconvert, or script Mac audio from the terminal.
/audio-jackRoute professional low-latency audio with JACK Audio Connection Kit (jackaudio.org): jackd server (ALSA/CoreAudio/PortAudio/ASIO backends), jack_control (D-Bus JACK2 config), jack_lsp (list ports/connections), jack_connect/jack_disconnect (manage links), jack_cpu_load, jack_samplerate, jack_bufsize (runtime period size), jack_transport, jack_rec (multi-channel WAV recording), jack_iodelay (round-trip latency), jack_wait, jack_midi_dump. JACK1 C maintenance vs JACK2 C++ multicore. Modern Linux swaps jackd for PipeWire's libjack shim — same client API. JackTrip for uncompressed multichannel UDP over the Internet. Use when the user asks to run a JACK server, connect audio clients, measure roundtrip latency, record from JACK ports, set JACK period size, or bridge JACK over the network with JackTrip.
Other plugins' skills for the same job