A simple Flask-based OCR (Optical Character Recognition) server using EasyOCR to extract text from images. The Docker image is optimized for CPU inference.
- RESTful API for processing images and extracting text
- Bounding box coordinates for each detected text element
- Confidence scores for each detection
- Docker support for easy deployment
- Pre-downloaded English language models
- Python 3.10
- Flask
- EasyOCR
- OpenCV
- NumPy
The Docker image is optimized for CPU inference.
# Build the Docker image
docker build -t ocr-server .
# Run the container
docker run -p 8000:8000 ocr-serverThe server will be available at http://localhost:8000.
# Install dependencies
pip install flask easyocr opencv-python numpy
# Run the server
python ocr_server.pyEndpoint: POST /process_image
Description: Processes an image and returns detected text with bounding box coordinates and confidence scores.
Request:
curl -X POST -F "image=@path/to/your/image.jpg" http://localhost:8000/process_imageResponse:
{
"result": [
{
"rect": {
"x": 100,
"y": 200,
"width": 150,
"height": 30
},
"value": "Detected text",
"prob": 0.9876
}
]
}Response Fields:
rect: Bounding box coordinatesx: X-coordinate of the top-left cornery: Y-coordinate of the top-left cornerwidth: Width of the bounding boxheight: Height of the bounding box
value: Detected textprob: Confidence score (0-1)
.
├── Dockerfile
├── ocr_server.py
├── README.md
└── sample_images/
- The server uses EasyOCR to detect text in images
- Bounding box coordinates are converted to a structured format (x, y, width, height)
- Confidence scores are provided for each text detection
- Results are returned as JSON
The Docker image is optimized for CPU inference, making it suitable for deployment on systems without dedicated GPUs.
The current implementation supports English. To add more languages, modify the ocr_server.py file:
reader = easyocr.Reader(['en', 'ru', 'fr'], gpu=False) # Add desired language codesThe server runs on 0.0.0.0:8000 by default. You can change the port by setting the PORT environment variable:
# Using Docker
docker run -p 8080:8080 -e PORT=8080 ocr-server
# Using manual installation
PORT=8080 python ocr_server.pyThe server will listen on the port specified by the PORT environment variable, or fall back to port 8000 if the variable is not set.
The API returns appropriate HTTP status codes:
200: Success400: Bad request (missing image file)500: Internal server error (processing error)
Error responses include a JSON body with an error message:
{
"error": "Description of the error"
}This project is licensed under the MIT License - see the LICENSE file for details.