If you've ever needed to extract text from a handwritten note, parse a medical prescription, or digitize a complex table from a scanned document, you know how frustrating OCR can be. Most APIs handle basic printed text well, but fall apart the moment the input gets messy.
Baidu's OCR API supports 19 different recognition scenarios, covering everything from standard text extraction to specialized tasks like handwriting recognition, mathematical formula parsing, and medical receipt processing. And with GoldBean, you can access all of them through a single unified API endpoint — no Baidu Cloud account required.
In this tutorial, I'll walk you through each scenario with real code examples.
What You'll Need
- A GoldBean API key (free tier: 50 calls/day, no signup needed)
- Node.js 18+ or Python 3.8+
- An image file to test with
The 19 OCR Scenarios at a Glance
| Category | Endpoints | Use Case |
|---|---|---|
| General Text | 4 | Basic, high-precision, low-light, web image |
| Handwriting | 1 | Hand-drawn notes and signatures |
| Form/Table | 2 | Structured forms and tables |
| ID Documents | 4 | ID cards, passports, business licenses, bank cards |
| Math & Formula | 1 | Mathematical expressions and equations |
| Medical | 2 | Medical prescriptions and hospital receipts |
| Vehicle | 2 | License plates and vehicle certificates |
| Specialized | 3 | QR codes, numbers, lottery tickets |
Quick Start: 5-Minute Integration
Node.js
import axios from 'axios';
const GOLDBEAN_API = 'https://goldbean-api.xyz/v1/ocr';
const API_KEY = 'your-goldbean-api-key';
async function recognizeImage(imagePath, ocrType) {
const fs = await import('fs');
const imageBuffer = fs.readFileSync(imagePath);
const base64Image = imageBuffer.toString('base64');
const response = await axios.post(GOLDBEAN_API, {
image: base64Image,
type: ocrType // e.g., 'handwriting', 'formula', 'medical_receipt'
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
}
});
return response.data;
}
// Example: Recognize handwritten text
const result = await recognizeImage('./handwritten-note.jpg', 'handwriting');
console.log(result.text);
Python
import base64
import requests
GOLDBEAN_API = 'https://goldbean-api.xyz/v1/ocr'
API_KEY = 'your-goldbean-api-key'
def recognize_image(image_path, ocr_type):
with open(image_path, 'rb') as f:
image_data = base64.b64encode(f.read()).decode('utf-8')
response = requests.post(
GOLDBEAN_API,
json={
'image': image_data,
'type': ocr_type
},
headers={
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
)
return response.json()
# Example: Parse a medical prescription
result = recognize_image('./prescription.jpg', 'medical_prescription')
print(result['data']['medicines'])
Deep Dive: 5 Most Useful Scenarios
1. Handwriting Recognition
Perfect for digitizing meeting notes, whiteboard photos, or old documents.
// Recognize handwritten English or Chinese text
const result = await recognizeImage('./notes.jpg', 'handwriting');
// Response includes:
// {
// "text": "Meeting notes: launch v2 by Friday",
// "words": [
// { "text": "Meeting", "location": {"left": 10, "top": 5, ...} },
// { "text": "notes:", "location": {...} }
// ],
// "probability": 0.97
// }
Key advantage: Works with both English and Chinese handwriting, including mixed-language documents.
2. Mathematical Formula Recognition
Upload a photo of an equation and get LaTeX back. This is a game-changer for education tech.
result = recognize_image('./equation.png', 'formula')
# Returns: { "formula": "E = mc^2", "latex": "E = mc^2" }
Supports fractions, integrals, summations, matrices, and multi-line equations.
3. Table Extraction
Extract structured data from tables in scanned documents or screenshots.
const result = await recognizeImage('./table-screenshot.png', 'table');
// Returns structured table data:
// {
// "tables": [
// {
// "header": ["Product", "Price", "Stock"],
// "rows": [
// ["Widget A", "$9.99", "142"],
// ["Widget B", "$14.99", "87"]
// ]
// }
// ]
// }
4. Medical Receipt Processing
Digitize hospital bills and insurance claims automatically.
result = recognize_image('./hospital-bill.jpg', 'medical_receipt')
# Returns structured data including:
# - Patient name
# - Total amount
# - Itemized charges
# - Hospital name and date
This is especially useful for insurance automation and medical expense tracking apps.
5. ID Card Recognition
Extract information from ID cards, passports, and business licenses.
const result = await recognizeImage('./id-card.jpg', 'id_card');
// Returns:
// {
// "name": "ZHANG SAN",
// "id_number": "110101199001011234",
// "address": "No.123 Main Street, Beijing",
// "birthday": "1990-01-01",
// "gender": "Male"
// }
Using with MCP (Model Context Protocol)
If you're using Cursor, Claude Desktop, or any MCP-compatible AI tool, you can call the OCR endpoints directly through the GoldBean MCP Server:
{
"mcpServers": {
"goldbean": {
"command": "npx",
"args": ["-y", "goldbean-mcp"],
"env": {
"GOLDBEAN_API_KEY": "your-api-key"
}
}
}
}
Once configured, just ask your AI assistant: "Read the text in this image" and it will automatically pick the right OCR scenario.
Pricing
Each OCR call costs just $0.001 through GoldBean — that's 10x cheaper than most Western OCR APIs. With the subscription plans, it gets even cheaper:
| Plan | Price | Calls/month | Cost per call |
|---|---|---|---|
| Free | $0 | 50/day | $0 |
| Starter | $5/mo | 5,000 | $0.001 |
| Monthly | $9.9/mo | 15,000 | $0.0007 |
| Yearly | $89/yr | 200,000 | $0.0005 |
Error Handling Best Practices
async function safeOCR(imagePath, ocrType) {
try {
const result = await recognizeImage(imagePath, ocrType);
if (result.error_code) {
switch (result.error_code) {
case 'IMAGE_TOO_LARGE':
// Compress and retry
break;
case 'NO_TEXT_FOUND':
console.log('No text detected in image');
break;
case 'RATE_LIMIT_EXCEEDED':
// Implement backoff
break;
}
}
return result;
} catch (error) {
if (error.response?.status === 402) {
// Insufficient credits - handle payment
console.error('Top up your credits at https://goldbean-api.xyz/buy-credits');
}
throw error;
}
}
Tips for Best Results
- Image quality matters. Minimum 300 DPI for printed text, 150 DPI for handwriting.
- Crop unnecessary borders. Focus on the text region for higher accuracy.
- Use the right scenario. Don't use general OCR for medical receipts — the specialized endpoint understands medical terminology.
- Handle rotation. If your image is rotated, the API can auto-detect up to 30-degree rotation, but extreme angles need pre-processing.
- Batch processing. For large volumes, use async processing to avoid timeouts.
Conclusion
Baidu's OCR API handles 19 different recognition scenarios that cover nearly every real-world use case — from casual handwriting to specialized medical and financial documents. Through GoldBean, you get a unified API that's 10x cheaper than alternatives like Google Cloud Vision or AWS Textract, with no Chinese phone number or Baidu Cloud account required.
The free tier gives you 50 calls per day with no signup, so you can start experimenting immediately.
Try GoldBean free: https://goldbean-api.xyz — 5 free calls/day, no signup needed
Top comments (0)