Documentation
¶
Index ¶
- Constants
- func InitRuntime(sharedLibraryPath string) error
- func RuntimeLibraryPath() string
- func ShutdownRuntime() error
- type CharsetRange
- type ClassifyOptions
- type ClassifyResult
- type ColorFilterOptions
- type Config
- type DetectionBox
- type DetectionConfig
- type DetectionEngine
- type DetectionOptions
- type Detector
- func (d *Detector) Close() error
- func (d *Detector) DetectBytes(data []byte) ([][]int, error)
- func (d *Detector) DetectBytesDetailed(data []byte) ([]DetectionBox, error)
- func (d *Detector) DetectBytesDetailedWithOptions(data []byte, options *DetectionOptions) ([]DetectionBox, error)
- func (d *Detector) DetectImageDetailed(img image.Image) ([]DetectionBox, error)
- func (d *Detector) DetectImageDetailedWithOptions(img image.Image, options *DetectionOptions) ([]DetectionBox, error)
- type HSVRange
- type LogFormat
- type Model
- type OCR
- func (o *OCR) Charset() []string
- func (o *OCR) ClassifyBytes(data []byte, options *ClassifyOptions) (string, error)
- func (o *OCR) ClassifyBytesDetailed(data []byte, options *ClassifyOptions) (*ClassifyResult, error)
- func (o *OCR) ClassifyImage(img image.Image, options *ClassifyOptions) (string, error)
- func (o *OCR) ClassifyImageDetailed(img image.Image, options *ClassifyOptions) (*ClassifyResult, error)
- func (o *OCR) Close() error
- func (o *OCR) Model() Model
- type OCRClient
- func (c *OCRClient) ClassifyBytes(ctx context.Context, image []byte, options *RemoteClassifyOptions) (*RemoteClassifyResult, error)
- func (c *OCRClient) DetectBytes(ctx context.Context, image []byte, options *RemoteDetectOptions) (*RemoteDetectResult, error)
- func (c *OCRClient) Ready(ctx context.Context) error
- func (c *OCRClient) SlideComparisonBytes(ctx context.Context, targetImage []byte, backgroundImage []byte) (*RemoteSlideComparisonResult, error)
- func (c *OCRClient) SlideMatchBytes(ctx context.Context, targetImage []byte, backgroundImage []byte, ...) (*RemoteSlideMatchResult, error)
- type OCRClientOption
- type OCREngine
- type OCRPool
- type PreprocessOptions
- type PreprocessResult
- type ProbabilityMatrix
- type RemoteClassifyOptions
- type RemoteClassifyResult
- type RemoteDetectOptions
- type RemoteDetectResult
- type RemoteError
- type RemoteSlideComparisonResult
- type RemoteSlideMatchOptions
- type RemoteSlideMatchResult
- type Server
- type ServerMetricsSnapshot
- type ServerOption
- type SlideResult
- func SlideComparisonBytes(targetData []byte, backgroundData []byte) (*SlideResult, error)
- func SlideComparisonImages(target image.Image, background image.Image) (*SlideResult, error)
- func SlideMatchBytes(targetData []byte, backgroundData []byte, simpleTarget bool) (*SlideResult, error)
- func SlideMatchImages(target image.Image, background image.Image, simpleTarget bool) (*SlideResult, error)
Constants ¶
View Source
const ( DefaultMaxImageBytes = 8 << 20 DefaultMaxBodyBytes = 12 << 20 )
View Source
const DefaultClientTimeout = 10 * time.Second
Variables ¶
This section is empty.
Functions ¶
func InitRuntime ¶
InitRuntime initializes ONNX Runtime once for the process.
If sharedLibraryPath is empty, the function first checks ONNXRUNTIME_SHARED_LIBRARY_PATH, then ONNXRUNTIME_HOME, then a local third_party/onnxruntime/<GOOS>_<GOARCH>/ directory, then an embedded runtime if this build includes one. Finally, it asks the system dynamic loader for the platform's default ONNX Runtime library name.
func RuntimeLibraryPath ¶
func RuntimeLibraryPath() string
RuntimeLibraryPath returns the path that initialized ONNX Runtime, or an empty string if InitRuntime has not succeeded yet.
func ShutdownRuntime ¶
func ShutdownRuntime() error
ShutdownRuntime releases the ONNX Runtime process-wide environment. Most long-running services do not need to call this until process shutdown.
Types ¶
type CharsetRange ¶
type CharsetRange struct {
// contains filtered or unexported fields
}
func NewCharsetRangeChars ¶
func NewCharsetRangeChars(chars []string) *CharsetRange
func NewCharsetRangeLimit ¶
func NewCharsetRangeLimit(maxIndex int) *CharsetRange
func NewCharsetRangeString ¶
func NewCharsetRangeString(chars string) *CharsetRange
type ClassifyOptions ¶
type ClassifyOptions struct {
PNGFix *bool
CharsetRange *CharsetRange
ColorFilter *ColorFilterOptions
Probability bool
}
type ClassifyResult ¶
type ClassifyResult struct {
Text string `json:"text"`
Confidence float64 `json:"confidence"`
Probability *ProbabilityMatrix `json:"probability,omitempty"`
}
type ColorFilterOptions ¶
type ColorFilterOptions struct {
Colors []string `json:"colors,omitempty"`
Ranges []HSVRange `json:"ranges,omitempty"`
}
func NewColorFilterColors ¶
func NewColorFilterColors(colors ...string) *ColorFilterOptions
func NewColorFilterRanges ¶
func NewColorFilterRanges(ranges ...HSVRange) *ColorFilterOptions
type DetectionBox ¶
type DetectionBox struct {
X1 int `json:"x1"`
Y1 int `json:"y1"`
X2 int `json:"x2"`
Y2 int `json:"y2"`
Score float64 `json:"score,omitempty"`
ClassID int `json:"class_id,omitempty"`
}
func (DetectionBox) Rect ¶
func (b DetectionBox) Rect() []int
type DetectionConfig ¶
type DetectionEngine ¶
type DetectionEngine interface {
DetectBytesDetailed(data []byte) ([]DetectionBox, error)
}
type DetectionOptions ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
func NewDetector ¶
func NewDetector(config DetectionConfig) (*Detector, error)
func (*Detector) DetectBytesDetailed ¶
func (d *Detector) DetectBytesDetailed(data []byte) ([]DetectionBox, error)
func (*Detector) DetectBytesDetailedWithOptions ¶
func (d *Detector) DetectBytesDetailedWithOptions(data []byte, options *DetectionOptions) ([]DetectionBox, error)
func (*Detector) DetectImageDetailed ¶
func (d *Detector) DetectImageDetailed(img image.Image) ([]DetectionBox, error)
func (*Detector) DetectImageDetailedWithOptions ¶
func (d *Detector) DetectImageDetailedWithOptions(img image.Image, options *DetectionOptions) ([]DetectionBox, error)
type HSVRange ¶
func (*HSVRange) UnmarshalJSON ¶
type OCR ¶
type OCR struct {
// contains filtered or unexported fields
}
func (*OCR) ClassifyBytes ¶
func (o *OCR) ClassifyBytes(data []byte, options *ClassifyOptions) (string, error)
func (*OCR) ClassifyBytesDetailed ¶
func (o *OCR) ClassifyBytesDetailed(data []byte, options *ClassifyOptions) (*ClassifyResult, error)
func (*OCR) ClassifyImage ¶
func (*OCR) ClassifyImageDetailed ¶
func (o *OCR) ClassifyImageDetailed(img image.Image, options *ClassifyOptions) (*ClassifyResult, error)
type OCRClient ¶
type OCRClient struct {
// contains filtered or unexported fields
}
func NewOCRClient ¶
func NewOCRClient(baseURL string, options ...OCRClientOption) *OCRClient
func (*OCRClient) ClassifyBytes ¶
func (c *OCRClient) ClassifyBytes(ctx context.Context, image []byte, options *RemoteClassifyOptions) (*RemoteClassifyResult, error)
func (*OCRClient) DetectBytes ¶
func (c *OCRClient) DetectBytes(ctx context.Context, image []byte, options *RemoteDetectOptions) (*RemoteDetectResult, error)
func (*OCRClient) SlideComparisonBytes ¶
func (*OCRClient) SlideMatchBytes ¶
func (c *OCRClient) SlideMatchBytes(ctx context.Context, targetImage []byte, backgroundImage []byte, options *RemoteSlideMatchOptions) (*RemoteSlideMatchResult, error)
type OCRClientOption ¶
type OCRClientOption func(*OCRClient)
func WithClientMaxImageBytes ¶
func WithClientMaxImageBytes(n int64) OCRClientOption
func WithClientTimeout ¶
func WithClientTimeout(timeout time.Duration) OCRClientOption
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) OCRClientOption
type OCREngine ¶
type OCREngine interface {
Model() Model
ClassifyBytesDetailed(data []byte, options *ClassifyOptions) (*ClassifyResult, error)
}
type OCRPool ¶
type OCRPool struct {
// contains filtered or unexported fields
}
func (*OCRPool) ClassifyBytesDetailed ¶
func (p *OCRPool) ClassifyBytesDetailed(data []byte, options *ClassifyOptions) (*ClassifyResult, error)
type PreprocessOptions ¶
type PreprocessOptions struct {
PNGFix bool
ColorFilter *ColorFilterOptions
}
type PreprocessResult ¶
type PreprocessResult struct {
Width int `json:"width"`
Height int `json:"height"`
Data []float32 `json:"data"`
}
func PreprocessOCRBytes ¶
func PreprocessOCRBytes(data []byte, options *PreprocessOptions) (*PreprocessResult, error)
func PreprocessOCRImage ¶
func PreprocessOCRImage(img image.Image, options *PreprocessOptions) (*PreprocessResult, error)
type ProbabilityMatrix ¶
type RemoteClassifyOptions ¶
type RemoteClassifyResult ¶
type RemoteClassifyResult struct {
Result string `json:"result"`
ProcessingTimeMS float64 `json:"processing_time_ms"`
RequestID string `json:"request_id,omitempty"`
Confidence float64 `json:"confidence,omitempty"`
Probability *ProbabilityMatrix `json:"probability,omitempty"`
}
type RemoteDetectOptions ¶
type RemoteDetectResult ¶
type RemoteDetectResult struct {
Result [][]int `json:"result"`
Boxes []DetectionBox `json:"boxes,omitempty"`
ProcessingTimeMS float64 `json:"processing_time_ms"`
RequestID string `json:"request_id,omitempty"`
}
type RemoteError ¶
func (*RemoteError) Error ¶
func (e *RemoteError) Error() string
type RemoteSlideComparisonResult ¶
type RemoteSlideComparisonResult struct {
Result SlideResult `json:"result"`
ProcessingTimeMS float64 `json:"processing_time_ms"`
RequestID string `json:"request_id,omitempty"`
}
type RemoteSlideMatchOptions ¶
type RemoteSlideMatchOptions struct {
SimpleTarget bool
}
type RemoteSlideMatchResult ¶
type RemoteSlideMatchResult struct {
Result SlideResult `json:"result"`
ProcessingTimeMS float64 `json:"processing_time_ms"`
RequestID string `json:"request_id,omitempty"`
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(ocr OCREngine, options ...ServerOption) *Server
func (*Server) Metrics ¶
func (s *Server) Metrics() ServerMetricsSnapshot
type ServerMetricsSnapshot ¶
type ServerMetricsSnapshot struct {
StartedAt string `json:"started_at"`
UptimeSeconds float64 `json:"uptime_seconds"`
TotalRequests uint64 `json:"total_requests"`
InFlightRequests int64 `json:"in_flight_requests"`
CompletedRequests uint64 `json:"completed_requests"`
ErrorRequests uint64 `json:"error_requests"`
StatusCodes map[string]uint64 `json:"status_codes"`
TotalLatencyMS float64 `json:"total_latency_ms"`
AverageLatencyMS float64 `json:"average_latency_ms"`
MaxLatencyMS float64 `json:"max_latency_ms"`
LastRequestAt string `json:"last_request_at,omitempty"`
LastRequestStatus int `json:"last_request_status,omitempty"`
LastRequestLatency float64 `json:"last_request_latency_ms,omitempty"`
}
type ServerOption ¶
type ServerOption func(*Server)
func WithDetector ¶
func WithDetector(detector DetectionEngine) ServerOption
func WithLogFormat ¶
func WithLogFormat(format LogFormat) ServerOption
func WithLogger ¶
func WithLogger(logger *log.Logger) ServerOption
func WithMaxBodyBytes ¶
func WithMaxBodyBytes(n int64) ServerOption
func WithMaxImageBytes ¶
func WithMaxImageBytes(n int64) ServerOption
type SlideResult ¶
type SlideResult struct {
Target []int `json:"target"`
TargetX int `json:"target_x"`
TargetY int `json:"target_y"`
Confidence float64 `json:"confidence,omitempty"`
}
func SlideComparisonBytes ¶
func SlideComparisonBytes(targetData []byte, backgroundData []byte) (*SlideResult, error)
func SlideComparisonImages ¶
func SlideMatchBytes ¶
func SlideMatchBytes(targetData []byte, backgroundData []byte, simpleTarget bool) (*SlideResult, error)
func SlideMatchImages ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.