sam2

package
v0.0.0-...-d793979 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MeanG = 0.456
	MeanB = 0.406
	MeanR = 0.485

	StdG = 0.224
	StdB = 0.225
	StdR = 0.229
)

均值和方差常量

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// 必填参数
	OnnxRuntimeLibPath string // onnxruntime.dll (或 .so, .dylib) 的路径
	EncodeModelPath    string // 图片特征提取模型
	DecodeModelPath    string // Mask解码模型

	// 可选参数
	UseCuda           bool // (可选) 是否启用 CUDA
	NumThreads        int  // (可选) ONNX 线程数, 默认由CPU核心数决定
	EnableCpuMemArena bool // (可选) 是否开启 ONNX 内存池
}

Config 配置项

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回默认配置

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine 持有 ONNX Session,负责创建 ImageContext

func NewEngine

func NewEngine(cfg Config) (*Engine, error)

NewEngine 初始化 sam2 引擎

func (*Engine) Destroy

func (e *Engine) Destroy() error

Destroy 释放相关资源

func (*Engine) EncodeImage

func (e *Engine) EncodeImage(img image.Image) (*ImageContext, error)

EncodeImage 图像特征提取

type ImageContext

type ImageContext struct {
	// contains filtered or unexported fields
}

ImageContext 包含特定图像的特征缓存和参数

func (*ImageContext) Decode

func (ctx *ImageContext) Decode(points []Point) (image.Image, float32, error)

Decode Mask解码并返回图片

func (*ImageContext) DecodeRaw

func (ctx *ImageContext) DecodeRaw(points []Point) (*Result, error)

DecodeRaw Mask解码并返回原始结果

func (*ImageContext) Destroy

func (ctx *ImageContext) Destroy()

Destroy 释放图像特征缓存

type Label

type Label int
const (
	LabelBackground  Label = 0 // 背景/排除
	LabelForeground  Label = 1 // 前景/点击
	LabelBoxTopLeft  Label = 2 // 框选左上
	LabelBoxBotRight Label = 3 // 框选右下
)

type Point

type Point struct {
	X, Y  float32
	Label Label
}

type Result

type Result struct {
	Mask   []uint8 // 0 or 255
	Score  float32
	Width  int
	Height int
}

Result Mask 预测结果

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL