API 文档
高精识别 API
高精度文字识别与位置检测,不仅提取文字内容,还提供每个文字块的详细坐标信息
概述
高精识别 API 提供高精度文字识别和详细的位置信息。与标准文字识别不同,该 API 不仅返回提取的文字内容,还返回每个文字块的精确坐标,包括旋转矩形和四点坐标。
该 API 使用统一的 JSON 请求格式,接受 URL 引用或 base64 编码的图像数据。
认证
API 支持以下认证方式:
- API 密钥: 通过查询参数传递您的 API 密钥
?key=YOUR_API_KEY
提取文字及位置数据
从图像文件中提取文字,并获取每个文字块的详细位置信息,包括旋转矩形和四点坐标。
请求
POST /api/advanced-recognition
参数:
参数 | 类型 | 必需 | 描述 |
---|---|---|---|
document | object | 是 | 文档对象 |
document.type | string | 是 | 固定值 "image_url" |
document.image_url | string | 是 | 图片 URL 或 base64 数据 |
filename | string | 否 | 文件名(base64 数据时推荐提供) |
key | string | 否 | API 密钥(查询参数,已登录用户可选) |
示例:
使用图片 URL:
curl -X POST "https://llmocr.com/api/advanced-recognition?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": {
"type": "image_url",
"image_url": "https://llmocr.com/image.jpg"
}
}'
使用 Base64 图片数据:
curl -X POST "https://llmocr.com/api/advanced-recognition?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": {
"type": "image_url",
"image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA..."
},
"filename": "document.jpg"
}'
响应
参数:
参数 | 类型 | 描述 |
---|---|---|
id | string | 数据库记录 ID |
filename | string | 文件名 |
content | string | 提取的文字内容(所有文字块用换行符连接) |
ocrResult | object | 包含位置信息的详细 OCR 结果 |
format | string | 输出格式,固定为 "json" |
timestamp | number | 处理完成时间戳 |
payload | string | API 端点 URL |
ocrResult.words_info 结构:
words_info 数组中的每一项包含:
字段 | 类型 | 描述 |
---|---|---|
text | string | 文字块的文本内容 |
location | number[] | 四点坐标 [x1,y1,x2,y2,x3,y3,x4,y4](左上 → 右上 → 右下 → 左下) |
rotate_rect | number[] | 旋转矩形 [center_x, center_y, width, height, angle],角度范围:[-90, 90] |
示例:
{
"id": "12345",
"filename": "document.jpg",
"content": "第一行文字\n第二行文字",
"ocrResult": {
"words_info": [
{
"text": "第一行文字",
"location": [150, 80, 400, 80, 400, 120, 150, 120],
"rotate_rect": [275, 100, 250, 40, 0]
},
{
"text": "第二行文字",
"location": [150, 150, 400, 150, 400, 190, 150, 190],
"rotate_rect": [275, 170, 250, 40, 0]
}
]
},
"format": "json",
"timestamp": 1640995200000,
"payload": "https://llmocr.com/api/advanced-recognition?key=YOUR_API_KEY"
}