imageToPatches

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DictPath = "ppocrv5_dict.txt" // PP-OCRv5 的字典文件路径,已提取为全局变量

)

Variables

This section is empty.

Functions

func InitORT

func InitORT()

initORT 初始化 ONNX Runtime 环境

func LoadDict

func LoadDict(path string)

LoadDict 加载字符字典,使用 sync.Once 确保只加载一次

func PrewarmLogitsPool

func PrewarmLogitsPool(size int, count int)

PrewarmLogitsPool 暴露给外部的预热接口 size: 预期的缓冲区大小(float32 数量) count: 预先填充多少个对象到池中

func SaveTextLinesToImages added in v1.0.1

func SaveTextLinesToImages(origImg image.Image, textLines []TextLine, outputDir string) error

SaveTextLinesToImages 将检测到的文本行保存为本地图片文件 origImg: 原始大图 textLines: 包含坐标信息的文本行切片 outputDir: 保存路径(如 "./debug_crops")

func SaveWithPadding added in v1.0.1

func SaveWithPadding(subImg image.Image, index int, outputDir string)

辅助技巧:如果你想在保存时给图片加一点白色边距(模拟 preprocessRec 的输入)

Types

type ClsEngine

type ClsEngine struct {
	Session *ort.DynamicAdvancedSession
}

func GetGlobalClsEngine

func GetGlobalClsEngine() (*ClsEngine, error)

func NewClsEngine

func NewClsEngine() (*ClsEngine, error)

func (*ClsEngine) ShouldRotate180

func (c *ClsEngine) ShouldRotate180(img image.Image) bool

Predict 判断是否需要翻转 (返回 true 表示需要旋转 180 度)

type DetEngine

type DetEngine struct {
	Session      *ort.AdvancedSession
	InputTensor  ort.Value
	OutputTensor ort.Value
	OutputData   []float32 // 预留给结果的切片
}

DetEngine 检测引擎

var (
	GlobalDetEngine *DetEngine
)

NewDetEngine 创建并初始化检测引擎

func GetGlobalDetEngine

func GetGlobalDetEngine() (*DetEngine, error)

获取(或初始化)全局引擎

func NewDetEngine

func NewDetEngine() (*DetEngine, error)

func (*DetEngine) Destroy

func (d *DetEngine) Destroy()

func (*DetEngine) DetectAndFixOrientation

func (d *DetEngine) DetectAndFixOrientation(src image.Image) ([]TextLine, error)

func (*DetEngine) GetBoxes

func (d *DetEngine) GetBoxes(srcImg image.Image) ([]image.Rectangle, error)

GetBoxes 只做推理并返回坐标框,不裁图

type RecEngine

type RecEngine struct {
	// 使用 DynamicAdvancedSession,它支持 RunWithBinding
	Session *ort.DynamicAdvancedSession
}

func GetGlobalRecEngine

func GetGlobalRecEngine() (*RecEngine, error)

GetGlobalRecEngine 获取全局唯一的识别引擎

func NewRecEngine

func NewRecEngine() (*RecEngine, error)

NewRecEngine 创建一个新的识别引擎实例

func (*RecEngine) Recognize

func (r *RecEngine) Recognize(inputData []float32, width int) (string, error)

Recognize 单行识别函数 (支持并行调用)

type RecognitionResult

type RecognitionResult struct {
	Index int
	Text  string
	Error error
}

RecognitionResult 代表每行文本的识别结果

func ImageToPatches

func ImageToPatches(srcImg image.Image) []RecognitionResult

type TextLine

type TextLine struct {
	Box   image.Rectangle // 在原图中的矩形框
	Score float32         // 检测得分
	Image image.Image     // 裁剪出的单行图片 (已转正)
}

TextLine 代表检测到的一个文字行

Jump to

Keyboard shortcuts

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