baiduocr

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

baiduocr 包的使用示例

只需要使用 baiduocr.NewClient 函数初始化客户端结构体变量 client,然后用 client.Accurateclient.General 方法识别图片得到结果 res,最后用 res.String() 返回格式化好的文字。

高精度版(client.Accurate)和通用版(client.General):百度大脑会限制每天免费识别的次数,高精度版识别次数较少,通用版识别次数较多。

识别代码:

import "gitee.com/rocket049/baiduocr"

//初始化客户端:baiduocr.NewClient(AppID, ApiKey, SecretKey string)
client,err := baiduocr.NewClient(AppID, ApiKey, SecretKey)
if err != nil {
	fmt.Println("请填入你在百度大脑申请的文字识别应用的 APP_ID、API_KEY、SECRET_KEY")
	panic(err)
}
//把图片数据读入 image 变量
img ,err := ioutil.ReadFile("jpg 或 png 文件")
if err != nil {
	panic(err)
}
//通用识别:client.General
res, err := client.General(img)
//高精度识别: client.Accurate(img []byte)
res, err := client.Accurate(img)
if err != nil {
	panic(err)
}
if res.ErrorCode != 0 {
    //输出错误信息
	fmt.Println(res.ErrorCode, res.ErrorMsg)
} else {
    //输出识别出的文字
	fmt.Println(res.String())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(id, apiKey, secKey string) (res *Client, err error)

func (*Client) Accurate

func (s *Client) Accurate(image []byte) (res *Result, err error)

Accurate 高精度识别

func (*Client) General added in v0.3.0

func (s *Client) General(image []byte) (res *Result, err error)

General 通用识别

func (*Client) Initial

func (s *Client) Initial() error

type Result

type Result struct {
	LogId          uint64         `json:"log_id"`
	WordsResultNum int            `json:"words_result_num"`
	WordsResult    []TWordsResult `json:"words_result"`
	ErrorCode      int            `json:"error_code"`
	ErrorMsg       string         `json:"error_msg"`
}

func (*Result) String

func (res *Result) String() string

type TLocation

type TLocation struct {
	Width  int `json:"width"`
	Top    int `json:"top"`
	Left   int `json:"left"`
	Height int `json:"height"`
}

type TWordsResult

type TWordsResult struct {
	Location TLocation `json:"location"`
	Words    string    `json:"words"`
}

type Token

type Token struct {
	RefreshToken  string `json:"refresh_token"`
	ExpiresIn     int    `json:"expires_in"`
	SessionKey    string `json:"session_key"`
	AccessToken   string `json:"access_token"`
	Scope         string `json:"scope"`
	SessionSecret string `json:"session_secret"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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