2 Star 3 Fork 2

rocket049 / baiduocr

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 1.21 KB
一键复制 编辑 原始数据 按行查看 历史

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())
}
Go
1
https://gitee.com/rocket049/baiduocr.git
git@gitee.com:rocket049/baiduocr.git
rocket049
baiduocr
baiduocr
master

搜索帮助