OCR图像识别
警告
使用 createTask 创建任务。
此接口无需单独获取结果,将直接返回图像识别结果!
任务 type
字段如下:
ImageToTextTask
创建任务
使用 createTask 创建任务。
任务对象结构
请注意,此类型的任务在 createTask 后直接返回任务执行结果,而不是通过 getTaskResult 异步获取。
属性 | 类型 | 是否必填 | 描述 |
---|---|---|---|
type | String | 是 | ImageToTextTask |
websiteURL | String | 否 | 页面源URL,用于提高准确性 |
body | String | 是 | 图片的base64编码内容(无换行符,无data:image/***;charset=utf-8;base64,) |
images | List[string] | 否 | 仅限number 模块,每次最多支持9张base64编码的图片 |
module | String | 否 | 指定模块。所有支持的模型如下表所示 |
独立模块支持
Module | Questions | Samples | Accuracy | LastUpdate |
---|
示例请求
POST https://api.capsolver.com/createTask
Host: api.capsolver.com
Content-Type: application/json
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "ImageToTextTask",
"websiteURL": "https://xxxx.com",
// 你可以选择需要的模块
// ocr 单图模型,默认 common
"module": "common",
// base64编码的图片
"body": "/9j/4AAQSkZJRgABA......"
}
}
如果图片中只有数字,建议使用 number
模块。示例请求:
{
"clientKey": "YOUR_API_KEY",
"task": {
"type": "ImageToTextTask",
"websiteURL": "https://xxxx.com",
"module": "number",
// 放置最多9张图片
"images": [
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA...",
"/9j/4AAQSkZJRgABAQA..."
]
}
}
示例响应
{
"errorId": 0,
"errorCode": "",
"errorDescription": "",
"status": "ready",
"solution": {
"text": "44795sds",
// number 模块:
"answers": ["100", "1330", "147", "248", "303", "439", "752", "752", "752"],
},
"taskId": "..."
}
使用SDK请求
# pip install --upgrade capsolver
# export CAPSOLVER_API_KEY='...'
import capsolver
capsolver.api_key = "..."
solution = capsolver.solve({
"type": "ImageToTextTask",
"module": "common",
"body": "/9j/4AAQSkZJRgABA......"
})
print(solution)