> Disclaimer:
> 1. 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.
> 2. 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.
bash <(curl -s https://raw.githubusercontent.com/xx235300/BaiduOCR-LocalFallback/main/install.sh)
# 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
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")
| API | Description |
|---|---|
| ----- | ------------- |
general | General text (with location) |
general_basic | General text (basic) |
accurate | High-accuracy (with location) |
accurate_basic | High-accuracy (basic) |
| API | Description |
|---|---|
| ----- | ------------- |
idcard | ID card |
bankcard | Bank card |
passport | Passport |
business_license | Business license |
| API | Description |
|---|---|
| ----- | ------------- |
receipt | General receipt |
vat_invoice | VAT invoice |
taxi_receipt | Taxi receipt |
train_ticket | Train ticket |
invoice | Invoice |
| API | Description |
|---|---|
| ----- | ------------- |
handwriting | Handwriting recognition |
table | Table recognition |
formula | Formula recognition |
Run python3 scripts/ocr.py --show-apis for the full list.
python3 scripts/ocr.py --configure
export BAIDU_OCR_API_KEY="<your_api_key>"
export BAIDU_OCR_SECRET_KEY="<your_secret_key>"
mkdir -p ~/.openclaw/skills/BaiduOCR-LocalFallback
cat > ~/.openclaw/skills/BaiduOCR-LocalFallback/config.json << 'EOF'
{
"api_key": "<your_api_key>",
"secret_key": "<your_secret_key>"
}
EOF
chmod 600 ~/.openclaw/skills/BaiduOCR-LocalFallback/config.json
{
"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"
}
}
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}")
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
Check if fallback is disabled:
ocr = OCR(use_fallback=False) # Fallback disabled
First run requires downloading models (~100MB). Pre-initialize:
from scripts.local_ocr import local_ocr
local_ocr._init_reader() # Warm up
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")
# 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")
Web images must be publicly accessible. Ensure:
import os
os.environ['REQUESTS_CA_BUNDLE'] = '/path/to/ca-bundle.crt'
Baidu Cloud Documentation Center
MIT © 2026 xx235300
共 1 个版本