|
|
||
|---|---|---|
| app | ||
| README.md | ||
| requirements.txt | ||
README.md
fastapi-vision-ocr
一个更轻的 macOS OCR API 示例:
FastAPI提供 HTTP 接口pyobjc-framework-Vision直接调用VNRecognizeTextRequest- 接收
multipart/form-data图片上传
要求
- macOS
- Python 3.11+
- Xcode Command Line Tools
安装
cd /Users/amy/Documents/workspace/ecommer-codebase/fastapi-vision-ocr
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
启动
cd /Users/amy/Documents/workspace/ecommer-codebase/fastapi-vision-ocr
source .venv/bin/activate
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
测试
健康检查:
curl http://127.0.0.1:8000/health
OCR:
curl -X POST http://127.0.0.1:8000/ocr \
-F "image=@/absolute/path/to/test.png" \
-F "recognition_level=accurate" \
-F "languages=zh-Hans" \
-F "languages=en-US"
返回:
{
"text": "hello\nworld",
"lines": [
{
"text": "hello",
"confidence": 0.99
},
{
"text": "world",
"confidence": 0.98
}
]
}
说明
- 这个服务只适合跑在 macOS,因为底层依赖 Apple Vision.framework。
- 这是 MVP 方案,目标是先把“上传图片返回文本”快速跑通。