高精識別 API

高精度文字識別與位置檢測,不僅提取文字內容,還提供每個文字塊的詳細坐標信息

概述

高精識別 API 提供高精度文字識別和詳細的位置信息。與標準文字識別不同,該 API 不僅返回提取的文字內容,還返回每個文字塊的精確坐標,包括旋轉矩形和四點坐標。

該 API 使用統一的 JSON 請求格式,接受 URL 引用或 base64 編碼的圖像數據。

認證

API 支持以下認證方式:

  • API 密鑰: 通過查詢參數傳遞您的 API 密鑰 ?key=YOUR_API_KEY

提取文字及位置數據

從圖像文件中提取文字,並獲取每個文字塊的詳細位置信息,包括旋轉矩形和四點坐標。

請求

POST /api/advanced-recognition

參數:

參數類型必需描述
documentobject文檔對象
document.typestring固定值 "image_url"
document.image_urlstring圖片 URL 或 base64 數據
filenamestring文件名(base64 數據時推薦提供)
keystringAPI 密鑰(查詢參數,已登錄用戶可選)

示例:

使用圖片 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"
  }'

響應

參數:

參數類型描述
idstring數據庫記錄 ID
filenamestring文件名
contentstring提取的文字內容(所有文字塊用換行符連接)
ocrResultobject包含位置信息的詳細 OCR 結果
formatstring輸出格式,固定為 "json"
timestampnumber處理完成時間戳
payloadstringAPI 端點 URL

ocrResult.words_info 結構:

words_info 數組中的每一項包含:

字段類型描述
textstring文字塊的文本內容
locationnumber[]四點坐標 [x1,y1,x2,y2,x3,y3,x4,y4](左上 → 右上 → 右下 → 左下)
rotate_rectnumber[]旋轉矩形 [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"
}
高精識別 API - LLMOCR Developer Guide