图像设计
- 作者仓库星标 3,284
- 作者更新于 实时读取
- 作者仓库 SenseNova-Skills
- 领域
- 数据
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @OpenSenseNova · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 需要 · Vendor-specific
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 读取环境变量
- 网络行为
- 允许外网请求
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: sn-da-image-caption
description: 图片理解与数据提取 skill。当图片文件(.png/.jpg/.jpeg/.gif/.webp/.bmp)是主要输入且用户需要理解、提取数据或分析图片内容时使用。提供预配置的 caption…
category: 数据
runtime: Python
---
# sn-da-image-caption 输出预览
## PART A: 任务判断
- 适用问题:表格、CSV、数据集、指标或分析流程。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Overview / scripts/caption.py — Image Caption / Usage”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于表格、CSV、数据集、指标或分析流程,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Overview / scripts/caption.py — Image Caption / Usage”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、读取环境变量、会按任务需要访问外部网络、需要准备 Vendor-specific API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;会按任务需要访问外部网络;需要准备 Vendor-specific API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文出现了 `/mnt` 这类斜杠命令;如果你的 Agent 支持命令触发,优先用命令开场,再补充目标和边界。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令、读取环境变量。
先用一个小任务确认它会围绕“Overview / scripts/caption.py — Image Caption / Usage”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: sn-da-image-caption
description: 图片理解与数据提取 skill。当图片文件(.png/.jpg/.jpeg/.gif/.webp/.bmp)是主要输入且用户需要理解、提取数据或分析图片内容时使用。提供预配置的 caption…
category: 数据
source: OpenSenseNova/SenseNova-Skills
---
# sn-da-image-caption
## 什么时候使用
- 把数据处理方向的常用动作沉淀成 Agent 可调用的技能 适合处理表格、CSV、指标、数据集、分析和可视化报告,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步…
- 面向表格、CSV、数据集、指标或分析流程,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Overview / scripts/caption.py — Image Caption / Usage」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;会按任务需要访问外部网络;需要准备 Vendor-specific API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "sn-da-image-caption" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Overview / scripts/caption.py — Image Caption / Usage
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Python | 读取文件、写入/修改文件、执行终端命令、读取环境变量 | 会按任务需要访问外部网络
安全层 -> 需要准备 Vendor-specific API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Image Caption Analysis — 图片描述与数据提取
Overview
Analyze, extract data from, or understand image files (.png, .jpg, .jpeg, .gif, .webp, .bmp). The core workflow:
- Run
scripts/caption.pyto get a text description of the image - Parse the description into structured data (DataFrame, etc.)
- Analyze, visualize, or export
scripts/caption.py — Image Caption
The script converts images to text descriptions via a vision model. Configure via SN_API_KEY (minimum required), or use SN_VISION_API_KEY / SN_VISION_BASE_URL / SN_VISION_MODEL for fine-grained control. See the project environment variable spec for the full fallback chain.
Usage
# Basic — get text description
python3 scripts/caption.py /mnt/data/image.png
# Custom prompt — guide what to extract
python3 scripts/caption.py /mnt/data/chart.png --prompt "提取所有数值,Markdown 表格格式"
# JSON output — includes detected type, usage stats, cache info
python3 scripts/caption.py /mnt/data/image.png --json
# Batch — process all images in a directory
python3 scripts/caption.py /mnt/data/images/ --batch --output /mnt/data/captions.json
# Override model (optional)
python3 scripts/caption.py /mnt/data/image.png --model gemini-3.1-flash-lite-preview
Options
| Option | Description |
|---|---|
--prompt, -p |
Custom prompt (overrides auto-detection) |
--model, -m |
Vision model (default: sensenova-6.7-flash-lite) |
--json |
Output structured JSON instead of plain text |
--batch |
Process all images in a directory |
--output, -o |
Output file for batch results |
--no-cache |
Skip MD5 cache |
What it does automatically
- Type detection: Detects image type from filename (chart/table/UI/diagram/general) and picks the best prompt
- Compression: Images >5MB or >2048px are compressed before sending
- Caching: Same image + same prompt → instant cached result, no API cost
- Error handling: Retries on failure, returns error message on permanent failure
JSON output format
{
"file": "/mnt/data/image.png",
"type": "chart",
"description": "这是一张柱状图...",
"usage": {"prompt_tokens": 1100, "completion_tokens": 400},
"cached": false
}
Calling from Python
import subprocess, json
CAPTION = "/path/to/skills/sn-da-image-caption/scripts/caption.py"
# Single image
result = subprocess.run(
["python3", CAPTION, "/mnt/data/chart.png", "--json",
"--prompt", "提取图表数据,Markdown 表格输出"],
capture_output=True, text=True, timeout=60
)
data = json.loads(result.stdout)
description = data["description"]
# Batch
result = subprocess.run(
["python3", CAPTION, "/mnt/data/images/", "--batch",
"--output", "/mnt/data/captions.json"],
capture_output=True, text=True, timeout=300
)
with open("/mnt/data/captions.json") as f:
all_captions = json.load(f)
Prompt Strategy
Different image types need different prompts. The script auto-detects, but specifying --prompt gives better results.
| Image Type | When | Recommended --prompt |
|---|---|---|
| Data chart | 柱状图/折线图/饼图 | "提取图表标题、坐标轴、每个数据点数值、图例。Markdown 表格输出。" |
| Table screenshot | 表格截图 | "提取表格所有内容,Markdown 表格格式,保持行列结构,数值不四舍五入。" |
| UI screenshot | 界面截图 | "以前端开发者视角描述:布局、组件、文字、颜色。" |
| Diagram | 流程图/架构图 | "描述所有节点、连接关系(A→B)、分支条件。" |
| General | 照片、其他 | 不传 --prompt,用默认 |
Parsing Caption Results
Caption 通常返回 Markdown 表格,解析为 DataFrame:
import pandas as pd
def parse_markdown_table(text):
lines = text.strip().split('\n')
table_lines = []
in_table = False
for line in lines:
stripped = line.strip()
if '|' in stripped:
in_table = True
table_lines.append(stripped)
elif in_table:
break
data_lines = []
for l in table_lines:
cells = [c.strip() for c in l.split('|') if c.strip()]
if cells and not all(set(c) <= set('-: ') for c in cells):
data_lines.append(cells)
if len(data_lines) < 2:
return None
header = data_lines[0]
rows = [r for r in data_lines[1:] if len(r) == len(header)]
df = pd.DataFrame(rows, columns=header)
# Auto numeric conversion
for col in df.columns:
try:
cleaned = df[col].str.replace(',', '').str.strip()
if cleaned.str.endswith('%').any():
df[col] = pd.to_numeric(cleaned.str.rstrip('%'), errors='coerce')
else:
converted = pd.to_numeric(cleaned, errors='coerce')
if converted.notna().sum() > len(df) * 0.5:
df[col] = converted
except Exception:
pass
return df
Visualization
Chinese Font Setup (MANDATORY)
import matplotlib.pyplot as plt
import matplotlib
import os
font_path = '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc'
if os.path.exists(font_path):
matplotlib.rcParams['font.family'] = 'WenQuanYi Zen Hei'
matplotlib.rcParams['axes.unicode_minus'] = False
Color Palette
COLORS = ['#4C72B0', '#55A868', '#C44E52', '#8172B2', '#CCB974', '#64B5CD']
Save & Display
plt.savefig('/mnt/data/chart.png', dpi=150, bbox_inches='tight')
plt.show()
print("")
Export to Excel
from openpyxl.styles import Font, PatternFill, Alignment
output_path = "/mnt/data/result.xlsx"
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
df.to_excel(writer, index=False, sheet_name='提取数据')
ws = writer.sheets['提取数据']
fill = PatternFill(start_color='4472C4', end_color='4472C4', fill_type='solid')
for cell in ws[1]:
cell.font = Font(bold=True, color='FFFFFF')
cell.fill = fill
cell.alignment = Alignment(horizontal='center')
for i, col in enumerate(df.columns, 1):
w = max(df[col].astype(str).str.len().max(), len(str(col))) + 2
ws.column_dimensions[chr(64 + i)].width = min(w * 1.2, 40)
print(f"[下载](sandbox:{output_path})")
Multi-Image Processing
import glob
image_files = sorted(glob.glob("/mnt/data/*.png"))
all_dfs = []
for img in image_files:
r = subprocess.run(
["python3", CAPTION, img, "--json", "--prompt", "提取数据,Markdown 表格"],
capture_output=True, text=True, timeout=60
)
desc = json.loads(r.stdout)["description"]
df = parse_markdown_table(desc)
if df is not None:
all_dfs.append(df)
combined = pd.concat(all_dfs, ignore_index=True) if all_dfs else None
Or batch mode:
python3 scripts/caption.py /mnt/data/images/ --batch --output /mnt/data/captions.json
Common Pitfalls
- Always caption first — don't guess image content from filenames
- Use --prompt for precision — auto-detect is OK, explicit prompt is better
- Verify extracted data — check sums, percentages, row counts after parsing
- Large tables truncate — caption in two passes:
"提取前半部分"+"提取后半部分" - Chinese font — must set before any matplotlib call, or output is garbled
- Timeout — single image ~10-30s, batch set timeout accordingly
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核