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 从图像对象检测(不截屏)。