paddleocr

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 11 Imported by: 0

README

English|中文

paddleocr

Go Reference Go Report Card

A simple wrapper for hiroi-sora/PaddleOCR-json implemented in Go language.

Installation

  1. Download the program from PaddleOCR-json releases and decompress it.

  2. install paddleocr

    go get github.com/doraemonkeys/paddleocr
    

Quick Start

package main

import (
	"fmt"

	"github.com/doraemonkeys/paddleocr"
)

func main() {
	p, err := paddleocr.NewPpocr("path/to/PaddleOCR-json.exe",
		paddleocr.OcrArgs{})
	if err != nil {
		panic(err)
	}
	defer p.Close()
	result, err := p.OcrFileAndParse(`path/to/image.png`)
	if err != nil {
		panic(err)
	}
	if result.Code != paddleocr.CodeSuccess {
		fmt.Println("orc failed:", result.Msg)
		return
	}
	fmt.Println(result.Data)
}

Documentation

Index

Constants

View Source
const (
	ConfigChinese    = "models/config_chinese.txt"
	ConfigChineseCht = "models/config_chinese_cht.txt"
	ConfigCyrillic   = "models/config_cyrillic.txt"
	ConfigEn         = "models/config_en.txt"
	ConfigFrenchV2   = "models/config_french_v2.txt"
	ConfigGermanV2   = "models/config_german_v2.txt"
	ConfigJapan      = "models/config_japan.txt"
	ConfigKorean     = "models/config_korean.txt"
)
View Source
const (
	// CodeSuccess indicates that the OCR process was successful.
	CodeSuccess = 100
	// CodeNoText indicates that no text was recognized.
	CodeNoText = 101
)

Variables

This section is empty.

Functions

func OcrFile

func OcrFile(exePath, imagePath string, argsCnf OcrArgs) ([]byte, error)

OcrFile processes the OCR for a given image file path using the specified OCR arguments. It returns the raw OCR result as bytes and any error encountered.

Types

type Data added in v1.0.2

type Data struct {
	Rect  [][]int `json:"box"`
	Score float32 `json:"score"`
	Text  string  `json:"text"`
}

type OcrArgs

type OcrArgs struct {
	// 启用cls方向分类,识别方向不是正朝上的图片。默认为false。
	Cls *bool `paddleocr:"cls"`
	// 启用CPU推理加速,关掉可以减少内存占用,但会降低速度。默认为true。
	EnableMkldnn *bool `paddleocr:"enable_mkldnn"`
	// 若图片长边长度大于该值,会被缩小到该值,以提高速度。默认为960。
	// 如果对大图/长图的识别率低,可增大 limit_side_len 的值。
	// 建议为 32 & 48 的公倍数,如 960, 2880, 4320
	LimitSideLen *int32 `paddleocr:"limit_side_len"`
	// 启用方向分类,必须与cls值相同。 默认为false。
	UseAngleCls *bool `paddleocr:"use_angle_cls"`
	// 指定不同语言的配置文件路径,识别多国语言。
	// models 目录中,每一个 config_xxx.txt 是一组语言配置文件(如英文是congfig_en.txt)。
	// 只需将这个文件的路径传入 config_path 参数,即可切换为对应的语言。
	//
	// 例如:
	//   paddleocr.OcrArgs{ ConfigPath: paddleocr.ConfigChinese }
	ConfigPath string `paddleocr:"config_path"`
}

func (OcrArgs) CmdString

func (o OcrArgs) CmdString() string

type Ppocr

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

func NewPpocr

func NewPpocr(exePath string, args OcrArgs) (*Ppocr, error)

NewPpocr creates a new instance of the Ppocr struct with the provided executable path and OCR arguments. It initializes the OCR process and returns a pointer to the Ppocr instance and any error encountered.

It is the caller's responsibility to close the Ppocr instance when finished.

func (*Ppocr) Close

func (p *Ppocr) Close() error

Close cleanly shuts down the OCR process associated with the Ppocr instance. It releases any resources and terminates the OCR process.

Warning: This method should only be called once.

func (*Ppocr) Ocr

func (p *Ppocr) Ocr(image []byte) ([]byte, error)

Ocr processes the OCR for a given image represented as a byte slice. It returns the OCR result as bytes and any error encountered.

func (*Ppocr) OcrAndParse

func (p *Ppocr) OcrAndParse(image []byte) (Result, error)

OcrAndParse processes and parses the OCR for a given image represented as a byte slice. It returns the parsed OCR results as a slice of Result structs and any error encountered.

func (*Ppocr) OcrClipboard

func (p *Ppocr) OcrClipboard() ([]byte, error)

OcrClipboard processes the OCR for an image stored in the clipboard. It returns the raw OCR result as bytes and any error encountered.

func (*Ppocr) OcrClipboardAndParse

func (p *Ppocr) OcrClipboardAndParse() (Result, error)

OcrClipboardAndParse processes the OCR for an image stored in the clipboard and parses the result. It returns the parsed OCR results as a slice of Result structs and any error encountered.

func (*Ppocr) OcrFile

func (p *Ppocr) OcrFile(imagePath string) ([]byte, error)

OcrFile sends an image file path to the OCR process and retrieves the OCR result. It returns the OCR result as bytes and any error encountered.

func (*Ppocr) OcrFileAndParse

func (p *Ppocr) OcrFileAndParse(imagePath string) (Result, error)

OcrFileAndParse processes the OCR for a given image file path and parses the result. It returns the parsed OCR results as a slice of Result structs and any error encountered.

type Result

type Result struct {
	Code int
	Msg  string
	Data []Data
}

func OcrFileAndParse

func OcrFileAndParse(exePath, imagePath string, argsCnf OcrArgs) (Result, error)

func ParseResult

func ParseResult(rawData []byte) (Result, error)

ParseResult parses the raw OCR result bytes into a slice of Result structs. It returns the parsed results and any error encountered during parsing.

Jump to

Keyboard shortcuts

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