Abstract
A Flask web service that accepts image uploads, sends them to Google Vision API for OCR, and returns structured text with bounding-box coordinates alongside a highlighted preview image. The interesting part is the clean split between machine-readable JSON output and a human-verifiable visual overlay, both derived from the same detection geometry.
1. What This Is
An early portfolio project (July 2022) that wraps Google Vision OCR behind a small Flask HTTP endpoint. The goal was to make OCR results consumable by other applications rather than only viewable in a browser. The service accepts an image upload, calls the Google Vision API, and returns both a JSON payload (recognized strings plus positional bounding boxes) and a processed preview image with detected text regions highlighted.
2. How It Works
| # | Stage | Input | Tool | Output |
|---|---|---|---|---|
| 01 | Upload | Image file (multipart form) | Flask | In-memory image buffer |
| 02 | OCR Inference | Image buffer | Google Vision API | Text strings + bounding-box polygons |
| 03 | Parse | Vision API response | Python | Structured text records + geometry |
| 04 | Highlight | Original image + geometry | Image drawing | Annotated preview image |
| 05 | Respond | Parsed data + preview | Flask JSON / file response | JSON payload + highlighted image |
3. Implementation Notes
3.1 Separation of inference and presentation
The same bounding-box geometry returned by Google Vision feeds two independent outputs: a JSON structure for programmatic consumers and a drawn overlay for visual verification. This keeps the API contract stable even if the preview rendering changes or is removed entirely.
3.2 Bounding-box geometry
Google Vision returns polygon vertices (typically four corners) per detected text block. The service maps these into application-friendly records and uses the same coordinates to draw rectangles on a copy of the uploaded image, so a reviewer can confirm which regions the OCR actually read.
4. Constraints
-
Single OCR provider
All inference goes through Google Vision. There is no fallback provider, so a Vision API outage or quota exhaustion takes the entire service down.
-
No authentication or rate limiting
The endpoint is open. Any client can upload images and consume the Google Vision quota without an API key or token on the Flask side.
-
Synchronous request cycle
The Flask worker blocks for the full duration of the Vision API call. Large images or slow network conditions tie up the request thread with no queue or timeout handling.
-
No test suite
The repository contains no automated tests for the parsing or geometry-mapping logic, so regressions in the JSON schema would only surface in manual use.
5. Next
- a. Add API-key authentication and per-client rate limiting in front of the Flask endpoint.
- b. Introduce a second OCR provider (e.g. Tesseract) behind a simple fallback chain so the service degrades gracefully when Vision is unavailable.
- c. Move OCR processing to a background task queue (Celery / RQ) so large or batch uploads do not block the web worker.
— end of report —