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"
}