package eventServer import ( "encoding/base64" "fmt" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions" ocr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr/v20181119" ) // CallLicensePlateRecognitionAPI 识别车牌 func CallLicensePlateRecognitionAPI(file []byte) (number string, err error) { // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密 credential := common.NewCredential( "SecretId", "SecretKey", ) // 实例化一个client选项 cpf := profile.NewClientProfile() cpf.HttpProfile.Endpoint = "ocr.tencentcloudapi.com" // 实例化要请求产品的client对象,clientProfile是可选的 client, _ := ocr.NewClient(credential, regions.Shanghai, cpf) // 实例化一个请求对象,每个接口都会对应一个request对象 request := ocr.NewLicensePlateOCRRequest() base64String := base64.StdEncoding.EncodeToString(file) request.ImageBase64 = common.StringPtr(base64String) // 返回的resp是一个LicensePlateOCRResponse的实例,与请求对象对应 response, err := client.LicensePlateOCR(request) if _, ok := err.(*errors.TencentCloudSDKError); ok { fmt.Printf("An API error has returned: %s", err) return } if err != nil { panic(err) } // 输出json格式的字符串回包 fmt.Printf("%s\n", response.ToJsonString()) fmt.Printf("车牌:%s\n", *response.Response.Number) return *response.Response.Number, err } type AutoGenerated struct { Response struct { Color string `json:"Color"` Confidence int `json:"Confidence"` LicensePlateInfos []struct { Color string `json:"Color"` Confidence int `json:"Confidence"` Number string `json:"Number"` Rect struct { Height int `json:"Height"` Width int `json:"Width"` X int `json:"X"` Y int `json:"Y"` } `json:"Rect"` } `json:"LicensePlateInfos"` Number string `json:"Number"` Rect struct { Height int `json:"Height"` Width int `json:"Width"` X int `json:"X"` Y int `json:"Y"` } `json:"Rect"` RequestID string `json:"RequestId"` } `json:"Response"` }