1
0
Fork 0
mirror of https://github.com/qazzxxx/ocr.git synced 2026-04-27 04:25:50 +03:00
No description
Find a file
2026-01-21 16:55:18 +08:00
.github/workflows feat: Add GitHub Actions workflow for Docker image publishing and configure API token environment variable in settings. 2026-01-21 11:46:07 +08:00
ocr refactor: Update OCR API endpoint definitions and processing logic. 2026-01-21 16:55:18 +08:00
.dockerignore chore: docker 2025-08-05 17:47:27 +08:00
.DS_Store chore: docker 2025-08-05 17:47:27 +08:00
db.sqlite3 项目初始化 2025-08-05 16:44:05 +08:00
docker-compose.yml chore: token 2026-01-21 13:41:53 +08:00
Dockerfile build: Switch Docker Compose to use a pre-built GHCR image, removing local build and development volume. 2026-01-21 11:49:34 +08:00
manage.py 项目初始化 2025-08-05 16:44:05 +08:00
ocr_api.log 项目初始化 2025-08-05 16:44:05 +08:00
README.md chore: token 2026-01-21 13:41:53 +08:00
requirements.txt chore: CORS 2026-01-21 13:46:58 +08:00

OCR API Service

这个项目提供了一个基于 RapidOCR 的文字识别 API 服务,支持 Docker 部署。

部署说明 (Deployment)

使用 Docker Compose 部署 (推荐)

该项目可以使用 Docker Compose 快速部署。

  1. 准备环境: 确保你已经安装了 Docker 和 Docker Compose。

    创建 docker-compose.yml 文件:

    version: "3.8"
    
    services:
      ocr-api:
        image: ghcr.io/qazzxxx/ocr:main
        container_name: ocr
        restart: always
        ports:
          - "6632:6632"
        environment:
          - TOKEN=your_secure_token
    

接口调用说明 (API Usage)

所有 API 请求都需要在 Header 中携带 token 进行验证。

识别图片文字

  • URL: /recognize
  • Method: POST
  • Header:
    • token: 你的 API Token (需要在环境变量中设置)
  • Body:
    • image: 图片文件 (multipart/form-data)

示例代码

使用 CURL

# 请将 your_secure_token 替换为你设置的 TOKEN
# 请将 image.png 替换为你要识别的图片路径

curl -X POST http://localhost:6632/recognize \
  -H "token: your_secure_token" \
  -F "image=@image.png"

使用 Python (Requests)

import requests

url = "http://localhost:6632/recognize"
token = "your_secure_token"
image_path = "path/to/image.png"

headers = {
    "token": token
}

files = {
    "image": open(image_path, "rb")
}

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

返回结果示例

{
    "status": "success",
    "full_text": "识别出的文字内容...",
    "details": [
        {
            "box": [[x1, y1], [x2, y1], [x2, y2], [x1, y2]],
            "text": "识别出的文字内容...",
            "confidence": 0.98
        }
    ]
}