baidu

package
v0.0.0-...-06f9d85 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

百度客户端 https://ai.baidu.com/ai-doc

https://ai.baidu.com/ai-doc/index/OCR

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	APIKey            string `env:"BAIDU_API_KEY"`
	SecretKey         string `env:"BAIDU_SECRET_KEY"`
	AccessToken       string
	AccessTokenExpire int64 // access token过期时间戳
}
var Baidu *Client

百度客户端,必须先调用Init或InitEnv初始化

func Init

func Init(api, secret string) (*Client, error)

Init 初始化百度客户端

func InitEnv

func InitEnv() (*Client, error)

InitEnv 初始化百度客户端 使用环境变量

func (*Client) GetAccessToken

func (b *Client) GetAccessToken() (string, error)

GetAccessToken 获取access token https://ai.baidu.com/ai-doc/REFERENCE/Ck3dwjhhu

func (*Client) OCR

func (b *Client) OCR(image string) (*OCRResult, error)

OCR 通用文字识别 https://ai.baidu.com/ai-doc/OCR/vk3h7y58v

type Location

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

type OCRResult

type OCRResult struct {
	LogID          uint64        `json:"log_id"`
	WordsResultNum uint32        `json:"words_result_num"`
	WordsResult    []WordsResult `json:"words_result"`
	ErrorCode      int           `json:"error_code"` // 错误码
	ErrorMsg       string        `json:"error_msg"`  // 错误描述
}

type TokenError

type TokenError struct {
	Error            string `json:"error"`             // 错误类型
	ErrorDescription string `json:"error_description"` // 错误描述
}

TokenError 获取access token失败响应

type TokenResult

type TokenResult struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"` // 多少秒后过期
}

TokenResult 获取access token成功响应

type WordsResult

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

Jump to

Keyboard shortcuts

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