Production-ready OCR model for building camera translation apps
Extract text with precise pixel coordinates β’ GPU-accelerated β’ Multi-language β’ Deploy to Replicate
import replicate
import json
output = replicate.run(
"zsxkib/easyocr",
input={
"image": "https://example.com/your-image.jpg",
"include_bboxes": True,
"preprocessing": True,
"min_confidence": 0.25
}
)
# Extract coordinates for overlay translation
metadata = json.loads(output["metadata"])
for region in metadata["regions"]:
text = region["text"]
x1, y1, x2, y2 = region["x1"], region["y1"], region["x2"], region["y2"]
# Now you can overlay translations at these exact coordinatesgit clone https://github.com/zsxkib/EasyOCR.git
cd EasyOCR
cog predict -i image=@your-image.jpg
cog push r8.im/your-username/easyocrPerfect for camera translation apps like Google Translate's camera feature:
- π Precise Coordinates: Get exact pixel positions for text overlay
- π― Layout Preservation: Maintains original text positioning and reading order
- π Multi-Language: 80+ languages with Unicode support
- β‘ GPU Optimized: Fast inference with automatic CPU fallback
- π± Mobile-Ready: Handles low-resolution screenshots and mobile captures
{
"image": "Screenshot or image file",
"languages": "Comma-separated codes (e.g., 'en,es,fr')",
"min_confidence": 0.25, # Filter low-confidence detections
"preprocessing": True, # Enhanced image processing
"include_bboxes": True, # Essential for coordinate overlay
"include_polygons": False # Optional detailed shapes
}{
"markdown": "path/to/extracted_text.md",
"metadata": {
"total_regions": 9,
"avg_confidence": 0.944,
"languages_used": ["en", "es"],
"regions": [
{
"text": "Hello World",
"confidence": 0.99,
"x1": 100, "y1": 50, # Top-left coordinates
"x2": 200, "y2": 80 # Bottom-right coordinates
}
// ... more text regions
]
}
}π± Camera Input
β
π Screenshot OCR (this model)
β
π Text + Coordinates Extracted
β
π Translation API (Google/Azure/etc.)
β
π¨ Overlay Translated Text
β
π± Augmented Camera View
This model handles the crucial first step: extracting text with pixel-perfect coordinates so you can overlay translations in the exact same positions.
Note: render_from_coordinates.py is a local helper for visualization; it is not included in the Replicate container or API.
Quick usage:
- Save OCR regions to a JSON file with a top-level key "regions", each item containing text, x1,y1,x2,y2
- Optionally pass a background image to draw on
Example:
python render_from_coordinates.py ocr_output.json --background path/to/image.png# Input: Screenshot of a menu
# Output: Structured regions ready for translation overlay
regions = [
{"text": "Pasta Carbonara", "x1": 120, "y1": 200, "x2": 280, "y2": 230},
{"text": "β¬12.50", "x1": 350, "y1": 200, "x2": 400, "y2": 230},
{"text": "Fresh ingredients", "x1": 120, "y1": 235, "x2": 260, "y2": 255}
]def translate_camera_view(image_path):
# Step 1: Extract text with coordinates
ocr_result = replicate.run("zsxkib/easyocr", input={"image": image_path})
regions = json.loads(ocr_result["metadata"])["regions"]
# Step 2: Translate each text region
for region in regions:
original_text = region["text"]
translated = translate_api(original_text, target_lang="es")
# Step 3: Overlay translation at exact coordinates
overlay_text(image, translated, region["x1"], region["y1"],
region["x2"], region["y2"])
return augmented_image- Framework: Cog + EasyOCR + PyTorch
- GPU: CUDA 12.1 with automatic CPU fallback
- Languages: 80+ supported with Unicode text
- Preprocessing: DPI upscaling, CLAHE enhancement, denoising
- Performance: Sub-second inference on typical screenshots
- Memory: Efficient cleanup prevents GPU memory leaks
βββ predict.py # Core OCR predictor
βββ cog.yaml # Deployment configuration
βββ requirements.txt # Minimal dependencies
βββ render_from_coordinates.py # Local helper for visualization (not in Replicate)
βββ README.md # This file
This is designed to be the minimal, focused OCR backbone for camera translation apps.
- Keep it simple and readable
- No unnecessary features or bloated code
- Focus on coordinate accuracy and performance
- World-class open source standards
MIT License β see LICENSE
Ready to build the next Google Translate Camera? This OCR foundation has you covered. β¨
π¦ Follow @zsxkib on X
π» Check out more projects @zsxkib on GitHub