Skip to content

OCR识别

简洁描述:使用 OCR 接口识别图片中的文本内容,并返回结构化的文本结果。


概览

  • 请求方法:POST
  • 路径:/task/gi/ocr
  • 内容类型:multipart/form-data

认证方式

  • Header:Authorization: Bearer <token>

请求示例

表单参数

参数类型必填说明
imagefile需要 OCR 识别的源图像文件

curl 示例

bash
curl -X POST "https://api.gpt.ge/task/gi/ocr" \
  -H "Authorization: Bearer sk-xxxx" \
  -F "image=@/path/to/image.png"

JavaScript (fetch) 示例

javascript
const formData = new FormData();
formData.append('image', fileInput.files[0]);

fetch('https://api.gpt.ge/task/gi/ocr', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-xxxx'
  },
  body: formData
}).then(r => r.json()).then(console.log);

Python(requests)示例

python
import requests

url = 'https://api.gpt.ge/task/gi/ocr'
headers = {
    'Authorization': 'Bearer sk-xxxx'
}
files = {
    'image': open('image.png', 'rb')
}

response = requests.post(url, headers=headers, files=files)
print(response.json())

返回示例(200)

json
{
  "text": "我是morphogen智能客服,小墨\n需要我的帮助吗?"
}

注意:此接口要求使用 multipart/form-data 上传图片文件,返回结果仅包含识别后的文本字段 text