Documentation
¶
Overview ¶
Package ddddocr provides local OCR, target detection, click-captcha ordering, and simple slider-captcha helpers backed by ONNX models.
The recommended entry point is Client:
client := ddddocr.NewClient(ddddocr.ClientConfig{})
result, err := client.ClickFile("captcha.jpg")
Model files and the ONNX Runtime shared library are loaded from the assets directory. By default the package first checks ./assets, then the assets directory beside the module source. Set ClientConfig.AssetsDir or ClientConfig.RuntimePath when deploying with custom paths.
Index ¶
- func DecodeImage(data []byte) (image.Image, error)
- func DefaultAssetsDir() string
- func DetectionPreprocess(img image.Image) ([]float32, float64)
- func LoadImageFile(path string) (image.Image, error)
- func OCRPreprocess(img image.Image, pngFix bool) ([]float32, int, int)
- func ReadInputFile(path string) ([]byte, error)
- func RunOCRFile(cfg OCRConfig) (any, error)
- func RunOCRImage(img image.Image, cfg OCRConfig) (any, error)
- type ClickCaptchaResult
- type Client
- func (c *Client) ClickFile(path string) (ClickCaptchaResult, error)
- func (c *Client) ClickImage(img image.Image) (ClickCaptchaResult, error)
- func (c *Client) DetectFile(path string) ([]DetectionBox, error)
- func (c *Client) DetectImage(img image.Image) ([]DetectionBox, error)
- func (c *Client) OCRFile(path string, opts OCROptions) (any, error)
- func (c *Client) OCRImage(img image.Image, opts OCROptions) (any, error)
- func (c *Client) SlideComparisonFile(targetPath, backgroundPath string) (SlideResult, error)
- func (c *Client) SlideMatchFile(targetPath, backgroundPath string, simple bool) (SlideResult, error)
- type ClientConfig
- type DetectionBox
- type DetectionConfig
- type OCRConfig
- type OCROptions
- type OCRProbability
- type SlideResult
- func RunSlideComparisonFile(targetPath, backgroundPath string) (SlideResult, error)
- func RunSlideMatchFile(targetPath, backgroundPath string, simple bool) (SlideResult, error)
- func SlideComparison(target, background image.Image) SlideResult
- func SlideMatch(target, background image.Image, simple bool) SlideResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeImage ¶
DecodeImage decodes image bytes into an image.Image.
func DefaultAssetsDir ¶
func DefaultAssetsDir() string
DefaultAssetsDir returns the default assets directory used by NewClient.
func DetectionPreprocess ¶
DetectionPreprocess converts an image into detection model input data.
func LoadImageFile ¶
LoadImageFile reads and decodes an image file.
func OCRPreprocess ¶
OCRPreprocess converts an image into OCR model input data.
func ReadInputFile ¶
ReadInputFile reads an image file into memory.
func RunOCRFile ¶
RunOCRFile recognizes text from an image file using the provided config.
Types ¶
type ClickCaptchaResult ¶
type ClickCaptchaResult struct {
Target [][]int `json:"target"`
}
ClickCaptchaResult contains click points ordered by the prompt sequence.
func ResolveClickCaptcha ¶
func ResolveClickCaptcha(img image.Image, boxes []DetectionBox) (ClickCaptchaResult, error)
ResolveClickCaptcha resolves ordered click points from a decoded image and precomputed detection boxes.
func RunClickCaptchaFile ¶
func RunClickCaptchaFile(cfg DetectionConfig) (ClickCaptchaResult, error)
RunClickCaptchaFile resolves ordered click points from an image file.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the high-level SDK entry point.
func NewClient ¶
func NewClient(cfg ClientConfig) *Client
NewClient creates a reusable ddddocr client.
func (*Client) ClickFile ¶
func (c *Client) ClickFile(path string) (ClickCaptchaResult, error)
ClickFile returns click points ordered according to the prompt icons.
func (*Client) ClickImage ¶
func (c *Client) ClickImage(img image.Image) (ClickCaptchaResult, error)
ClickImage returns ordered click points from an already decoded image.
func (*Client) DetectFile ¶
func (c *Client) DetectFile(path string) ([]DetectionBox, error)
DetectFile returns detection boxes in [x1, y1, x2, y2] format.
func (*Client) DetectImage ¶
func (c *Client) DetectImage(img image.Image) ([]DetectionBox, error)
DetectImage returns detection boxes from an already decoded image.
func (*Client) OCRFile ¶
func (c *Client) OCRFile(path string, opts OCROptions) (any, error)
OCRFile recognizes text from an image file.
func (*Client) SlideComparisonFile ¶
func (c *Client) SlideComparisonFile(targetPath, backgroundPath string) (SlideResult, error)
SlideComparisonFile locates a slider target by comparing two images.
func (*Client) SlideMatchFile ¶
func (c *Client) SlideMatchFile(targetPath, backgroundPath string, simple bool) (SlideResult, error)
SlideMatchFile locates a slider target by template matching.
type ClientConfig ¶
type ClientConfig struct {
// AssetsDir contains ONNX models, charsets.json, and optional runtime files.
// If empty, DefaultAssetsDir is used.
AssetsDir string
// RuntimePath points to the ONNX Runtime shared library. If empty, the
// client uses onnxruntime_arm64.dylib inside AssetsDir.
RuntimePath string
// UseBetaModel switches OCR from common_old.onnx/old charset to
// common.onnx/beta charset.
UseBetaModel bool
}
type DetectionBox ¶
type DetectionBox []int
DetectionBox is a rectangle in [x1, y1, x2, y2] pixel coordinates.
func RunDetectionFile ¶
func RunDetectionFile(cfg DetectionConfig) ([]DetectionBox, error)
RunDetectionFile detects target boxes from an image file.
func RunDetectionImage ¶
func RunDetectionImage(img image.Image, cfg DetectionConfig) ([]DetectionBox, error)
RunDetectionImage detects target boxes from a decoded image.
type DetectionConfig ¶
DetectionConfig configures the object detection model runtime.
type OCRConfig ¶
type OCRConfig struct {
ImagePath string
ModelPath string
CharsetPath string
CharsetName string
RuntimePath string
PNGFix bool
Probability bool
}
OCRConfig configures OCR model paths, runtime path, and preprocessing.
type OCROptions ¶
type OCROptions struct {
// PNGFix composites transparent PNG pixels over white before OCR.
PNGFix bool
// Probability returns OCRProbability instead of a plain string.
Probability bool
}
OCROptions controls OCR preprocessing and response shape.
type OCRProbability ¶
OCRProbability is returned by OCR when probability output is enabled.
type SlideResult ¶
type SlideResult struct {
Target []int `json:"target"`
TargetX int `json:"target_x"`
TargetY int `json:"target_y"`
Confidence *float64 `json:"confidence,omitempty"`
}
SlideResult contains a slider target point.
func RunSlideComparisonFile ¶
func RunSlideComparisonFile(targetPath, backgroundPath string) (SlideResult, error)
RunSlideComparisonFile locates a slider target by comparing two image files.
func RunSlideMatchFile ¶
func RunSlideMatchFile(targetPath, backgroundPath string, simple bool) (SlideResult, error)
RunSlideMatchFile locates a slider target from target and background files.
func SlideComparison ¶
func SlideComparison(target, background image.Image) SlideResult
SlideComparison locates a slider target by image difference.
func SlideMatch ¶
func SlideMatch(target, background image.Image, simple bool) SlideResult
SlideMatch locates a slider target by template matching.