# API 调用说明 - 基础地址:`https://ocr.hcshai.com` - 接口:`POST /ocr` - 请求方式:`multipart/form-data` - 请求参数: - `image`:必填,图片文件,支持 `png,jpg,jpeg,gif,bmp` ## 响应示例 ``` { "results": [ { "text": "示例文本", "confidence": 0.98, "position": { "points": [[x1,y1],[x2,y2],[x3,y3],[x4,y4]] } } ], "code": 200 } ``` ## 错误响应 ``` { "error": "No file provided" } { "error": "File type not allowed" } { "error": "No results found", "code": 404 } ``` ## Curl 示例 ``` # 使用请求头传入令牌(仅支持 Bearer 格式) curl -H "Authorization: Bearer " -X POST -F "image=@images/a.jpg" https://ocr.hcshai.com/ocr ``` ## Python 示例 ```python import requests url = "https://ocr.hcshai.com/ocr" token = "" headers = {"Authorization": f"Bearer {token}"} with open("images/a.jpg", 'rb') as f: files = {'image': f} resp = requests.post(url, files=files, headers=headers) print(resp.json()) ## Go 示例 ```go package main import ( "bytes" "fmt" "io" "mime/multipart" "net/http" "os" ) func main() { filePath := "images/a.jpg" token := "" url := "https://ocr.hcshai.com/ocr" file, err := os.Open(filePath) if err != nil { panic(err) } defer file.Close() body := &bytes.Buffer{} writer := multipart.NewWriter(body) part, err := writer.CreateFormFile("image", "a.jpg") if err != nil { panic(err) } if _, err := io.Copy(part, file); err != nil { panic(err) } writer.Close() req, err := http.NewRequest("POST", url, body) if err != nil { panic(err) } req.Header.Set("Content-Type", writer.FormDataContentType()) req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) resp, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer resp.Body.Close() fmt.Println("Status:", resp.Status) } ``` ```