Gomaton
指南
API
GitHub
指南
API
GitHub
  • 前言

    • 快速开始
    • 能力速查
    • 工作原理
    • 硬件输入后端(ESP32 HID)
  • API 参考

    • motion - 触控 / 输入
    • images - 找图找色 / 截图
    • uiacc - 控件(UI 树)
    • device - 设备
    • app - 应用
    • ime - 输入法
    • ocr - 文字识别
    • yolo - 目标检测
    • files - 文件
    • storages - 键值存储
    • https - 网络
    • media - 媒体
    • system - 系统
    • utils - 工具

yolo — 目标检测(YOLO)

import "gomaton.dev/sdk/yolo"

Package yolo 目标检测(YOLO,ncnn 推理)。cgo 薄封装,真身在 libyolo.so(二进制)。 用法:New(param, bin, labelsPath, targetSize, conf, nms) → Detect(区域)/DetectFromImage/Close。 模型为 ncnn 的 .param/.bin;放项目 resources/models/yolo/,用 files.Path 取路径。

New

func New(paramPath, binPath, labelsPath string, targetSize int, conf, nms float32) (*Yolo, error)

New 加载一个 ncnn YOLO 模型(param + bin)——用自己的模型就把这两个路径指到自己的文件。

  • labelsPath:类别文件,每行一个类名;传空用内置 COCO80(yolov8n 预训练顺序)。
  • targetSize:模型输入边长,yolov8 默认 640;按你的模型给。
  • conf / nms:置信度阈值与 NMS 阈值,默认 0.25 / 0.45。

加载失败返回 error(带底层 rc 与 param 路径)。

y, err := yolo.New(
	files.Path("models/yolo/best.param"),
	files.Path("models/yolo/best.bin"),
	files.Path("models/yolo/labels.txt"), // 空则用 COCO80
	640, 0.25, 0.45)

Yolo.Close

func (y *Yolo) Close()

Close 释放模型。

Yolo.Detect

func (y *Yolo) Detect(x1, y1, x2, y2 int) []Result

Detect 在屏幕像素区域内检测(x2/y2<=0 到边;坐标换算回全屏)。

Yolo.DetectFromImage

func (y *Yolo) DetectFromImage(img *image.NRGBA) []Result

DetectFromImage 从图像对象检测(不截屏)。

上次更新: 2026/9/2 06:21
贡献者: hb
Prev
ocr - 文字识别
Next
files - 文件