/install baiduocr-localfallback
BaiduOCR-LocalFallback
Disclaimer:
- This project is not an official Baidu product and has no affiliation with Baidu. This project only provides a wrapper for Baidu OCR API; users must apply for a Baidu Cloud account and comply with Baidu's terms of service.
- This project is 99% AI-generated. The AI's owner has no programming background. Please evaluate the project's feasibility before use.
115+ Baidu OCR API interfaces with EasyOCR local fallback — auto-switches to local recognition when the network is unstable.
Features
- ✅ 115+ OCR APIs - General, ID cards, receipts, documents, education, and more
- ✅ Local fallback - Integrates EasyOCR; auto-switches when Baidu OCR is unavailable
- ✅ Image preprocessing - Auto compresses and converts to fit the 4MB limit
- ✅ Token caching - access_token cached for 25 days
- ✅ Auto retry - Retries 3 times on network fluctuations
- ✅ Multiple config methods - Environment variables, config file, or interactive setup
Installation
One-click install
bash \x3C(curl -s https://raw.githubusercontent.com/xx235300/BaiduOCR-LocalFallback/main/install.sh)
Manual install
# 1. Clone the repo
git clone https://github.com/xx235300/BaiduOCR-LocalFallback.git
cd BaiduOCR-LocalFallback
# 2. Install dependencies
pip3 install -r requirements.txt
# 3. Configure API credentials
python3 scripts/ocr.py --configure
Quick Start
from scripts.ocr import OCR
ocr = OCR()
# General text recognition
result = ocr.recognize(image="/path/to/image.jpg", api="general_basic")
# ID card recognition
result = ocr.recognize(image="/path/to/idcard.jpg", api="idcard", id_card_side="front")
# Handwriting (local fallback)
result = ocr.recognize(image="/path/to/handwriting.jpg", api="handwriting")
Supported APIs
General Text
| API | Description |
|---|---|
general |
General text (with location) |
general_basic |
General text (basic) |
accurate |
High-accuracy (with location) |
accurate_basic |
High-accuracy (basic) |
ID & Cards
| API | Description |
|---|---|
idcard |
ID card |
bankcard |
Bank card |
passport |
Passport |
business_license |
Business license |
Receipts
| API | Description |
|---|---|
receipt |
General receipt |
vat_invoice |
VAT invoice |
taxi_receipt |
Taxi receipt |
train_ticket |
Train ticket |
invoice |
Invoice |
Handwriting / Documents
| API | Description |
|---|---|
handwriting |
Handwriting recognition |
table |
Table recognition |
formula |
Formula recognition |
More APIs (115+)
Run python3 scripts/ocr.py --show-apis for the full list.
Configuration
Method 1: Interactive
python3 scripts/ocr.py --configure
Method 2: Environment variables (recommended for security)
export BAIDU_OCR_API_KEY="\x3Cyour_api_key>"
export BAIDU_OCR_SECRET_KEY="\x3Cyour_secret_key>"
Method 3: Config file
mkdir -p ~/.openclaw/skills/BaiduOCR-LocalFallback
cat > ~/.openclaw/skills/BaiduOCR-LocalFallback/config.json \x3C\x3C 'EOF'
{
"api_key": "\x3Cyour_api_key>",
"secret_key": "\x3Cyour_secret_key>"
}
EOF
chmod 600 ~/.openclaw/skills/BaiduOCR-LocalFallback/config.json
Response Format
{
"words_result": [
{"words": "Recognized text", "location": {"vertices": [{"x": 0, "y": 0}, ...]}}
],
"words_result_num": 1,
"fallback_info": { // only present when using local fallback
"engine": "EasyOCR",
"message": "Baidu OCR unavailable, using local EasyOCR"
}
}
Error Handling
from scripts.ocr import OCR
from scripts.baidu_client import BaiduOCRError
ocr = OCR()
try:
result = ocr.recognize(image="/path/to/image.jpg")
except BaiduOCRError as e:
print(f"Baidu OCR error: {e.error_code} - {e.error_msg}")
except Exception as e:
print(f"Other error: {e}")
FAQ
Q: I have no coding experience, what should I do if an error occurs during use?
Just send the cloud document link to the AI and let it troubleshoot and find a solution on its own. Sample prompt:
Please troubleshoot and resolve the issue according to the skill usage documentation.
Skill Usage Documentation: https://my.feishu.cn/docx/Gjy0djSado5YqVxzO6ecYbOmn4g?from=from_copylink
Q: How to get Baidu OCR API credentials?
- Go to Baidu Cloud Console
- Search "OCR" or "文字识别"
- Create an app and enable the OCR services you need
- Get API Key and Secret Key from "My Apps"
Q: "Baidu OCR call failed" but no auto-switch to local fallback?
Check if fallback is disabled:
ocr = OCR(use_fallback=False) # Fallback disabled
Q: EasyOCR initialization is slow?
First run requires downloading models (~100MB). Pre-initialize:
from scripts.local_ocr import local_ocr
local_ocr._init_reader() # Warm up
Q: How to handle Base64 images?
import base64
# Read image and convert to Base64
with open("image.jpg", "rb") as f:
img_base64 = base64.b64encode(f.read()).decode()
result = ocr.recognize(image=img_base64, api="general_basic")
Q: How to specify output format?
# Table - returns Excel
result = ocr.recognize(image="table.jpg", api="table", request_type="excel")
# Table - returns JSON
result = ocr.recognize(image="table.jpg", api="table", request_type="json")
Q: Web image recognition failed?
Web images must be publicly accessible. Ensure:
- Image URL is publicly reachable
- Firewall allows outbound 80/443
- Try downloading locally first
Q: How to disable SSL certificate verification (dev only)?
import os
os.environ['REQUESTS_CA_BUNDLE'] = '/path/to/ca-bundle.crt'
Performance Tips
- First-time EasyOCR requires downloading models (~100MB), please be patient
- Recommended image size under 2MB for best performance
- Large images are auto-compressed and scaled
- access_token is auto-cached and refreshed
Related Documents
Baidu Cloud Documentation Center
License
MIT © 2026 xx235300
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install baiduocr-localfallback - 安装完成后,直接呼叫该 Skill 的名称或使用
/baiduocr-localfallback触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
BaiduOCR-LocalFallback 是什么?
Provides 115+ Baidu OCR APIs with automatic EasyOCR local fallback, image preprocessing, token caching, and auto-retry for stable text recognition. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 96 次。
如何安装 BaiduOCR-LocalFallback?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install baiduocr-localfallback」即可一键安装,无需额外配置。
BaiduOCR-LocalFallback 是免费的吗?
是的,BaiduOCR-LocalFallback 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
BaiduOCR-LocalFallback 支持哪些平台?
BaiduOCR-LocalFallback 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 BaiduOCR-LocalFallback?
由 xx235300(@xx235300)开发并维护,当前版本 v1.1.0。