Files
goldyard2025 3fe919e37c refactor(halcon): single-skill plugin layout → invoke as /halcon (not /halcon:halcon)
Move SKILL.md + references/ scripts/ evals/ from skills/halcon/ up to the
plugin root. Per Claude Code plugins-reference, a plugin with SKILL.md at its
root and no skills/ subdir is auto-loaded as a single-skill plugin (v2.1.142+),
so the invocation name = frontmatter name = halcon → clean /halcon.
Bump plugin.json 2.0.0 → 2.0.1 so existing installs receive the update.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-10 23:14:39 +08:00

31 lines
1.2 KiB
Python

"""ROI 示教工具:显示一张代表图,人工画一次矩形,存成 roi.hobj。运行一次即可。"""
import halcon as ha
IMG_DIR = r"C:\工作文档\2025.10.03_精度实验数据分析\两种找圆算法对比\初始状态-往复-右侧上视左标定片阵列Mark定位"
ROI_FILE = r"C:\workspace\agent-studio\halcon-001\roi.hobj"
# 取目录里第一张 png 作为代表图
files = ha.list_files(IMG_DIR, "files")
pngs = sorted(ha.tuple_regexp_select(files, r"\.png$"))
if not pngs:
raise SystemExit("目录里没有 png")
img = ha.read_image(pngs[0])
width, height = ha.get_image_size(img)
width, height = width[0], height[0]
# 开窗口,映射到整幅图坐标(这样画出来的框就是图像坐标)
win = ha.open_window(0, 0, 1024, 768, 0, "visible", "")
ha.set_part(win, 0, 0, height - 1, width - 1)
ha.disp_obj(img, win)
ha.set_color(win, "green")
print("请在弹出的窗口里用鼠标左键拖出 ROI 矩形,松开即可 ...", flush=True)
row1, col1, row2, col2 = ha.draw_rectangle1(win) # 阻塞,等人工画
rect = ha.gen_rectangle1(row1, col1, row2, col2)
ha.write_region(rect, ROI_FILE)
print(f"ROI 已保存: {ROI_FILE}")
print(f"矩形坐标 Row1={row1:.1f} Col1={col1:.1f} Row2={row2:.1f} Col2={col2:.1f}")
ha.close_window(win)