# baiduocr **Repository Path**: rocket049/baiduocr ## Basic Information - **Project Name**: baiduocr - **Description**: 用 go 语言实现的百度大脑文字识别客户端包和命令行客户端程序。 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 2 - **Created**: 2019-06-24 - **Last Updated**: 2022-10-27 ## Categories & Tags **Categories**: image-processing **Tags**: None ## README # baiduocr 包的使用示例 只需要使用 `baiduocr.NewClient` 函数初始化客户端结构体变量 `client`,然后用 `client.Accurate` 或 `client.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()) } ```