AgentSkillsCN

pywayne-cv-tools

OpenCV YAML 文件读写工具。在使用 pywayne.cv.tools 模块处理 OpenCV FileStorage YAML 文件时,可借助该工具轻松读取嵌套结构、NumPy 数组、基础类型及列表等数据。支持对 cv2.FileNode 的解析,包括 Map 节点、Seq 节点以及矩阵节点。

SKILL.md
--- frontmatter
name: pywayne-cv-tools
description: OpenCV YAML file read/write utilities. Use when working with pywayne.cv.tools module to read OpenCV FileStorage YAML files with support for nested structures, numpy arrays, basic types, and lists. Handles cv2.FileNode parsing including Map, Seq, and matrix nodes.

Pywayne CV YAML I/O

This module provides utilities for reading and writing OpenCV cv2.FileStorage YAML files.

Quick Start

python
from pywayne.cv.tools import read_cv_yaml, write_cv_yaml
import numpy as np

# Write to YAML file
data = {
    "camera_name": "test_camera",
    "image_width": 1920,
    "image_height": 1080,
    "calibration_matrix": np.eye(3)
}
write_cv_yaml('config.yaml', data)

# Read from YAML file
data = read_cv_yaml('config.yaml')
print(data)

Supported Data Types

TypeHandling
int, float, strWritten directly
np.ndarrayWritten using fs.write()
listWritten using FileNode_SEQ
dictWritten using FileNode_MAP
NoneSkipped

Reading Files

python
from pywayne.cv.tools import read_cv_yaml

# Read YAML file (returns dict or None on error)
data = read_cv_yaml('camera_config.yaml')
if data:
    print(data['camera_name'])
    print(data['image_width'])

Notes:

  • Handles nested structures recursively
  • Returns None if file cannot be opened
  • Uses wayne_print for error messages (red/yellow colors)
  • Supports both FileNode_MAP and FileNode_SEQ for dictionaries and lists
  • Matrix nodes read using .mat() method

Writing Files

python
from pywayne.cv.tools import write_cv_yaml

# Write data to YAML file
data = {
    "matrix": np.eye(3),
    "vector": [1, 2, 3]
}
success = write_cv_yaml('config.yaml', data)

if success:
    print("Write successful")

Notes:

  • Returns True on success, False on error
  • Handles lists with empty key convention for OpenCV
  • Supports unnamed sequences using empty key string
  • Skips None values during write

Requirements

  • cv2 (OpenCV) - For FileStorage operations
  • numpy - For numpy array handling
  • pywayne.tools - For wayne_print logging

API Reference

FunctionDescription
read_cv_yaml(path)Read OpenCV YAML file, returns dict or None
write_cv_yaml(path, data)Write dict to OpenCV YAML file, returns bool

File Structure Handling

The module handles OpenCV's cv2.FileNode types:

Node TypeHandling
MapUses .keys() method (requires callable)
SeqUses element iteration with recursive parsing
MatrixUses .mat() method
Int/Float/StringUses .real(), .int(), .string() methods