Skip to content

dreagledr/easyocr-cpu-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OCR Server

A simple Flask-based OCR (Optical Character Recognition) server using EasyOCR to extract text from images. The Docker image is optimized for CPU inference.

Features

  • 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

Requirements

  • Python 3.10
  • Flask
  • EasyOCR
  • OpenCV
  • NumPy

Installation

Using Docker (Recommended)

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-server

The server will be available at http://localhost:8000.

Manual Installation

# Install dependencies
pip install flask easyocr opencv-python numpy

# Run the server
python ocr_server.py

API Usage

Process Image

Endpoint: 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_image

Response:

{
  "result": [
    {
      "rect": {
        "x": 100,
        "y": 200,
        "width": 150,
        "height": 30
      },
      "value": "Detected text",
      "prob": 0.9876
    }
  ]
}

Response Fields:

  • rect: Bounding box coordinates
    • x: X-coordinate of the top-left corner
    • y: Y-coordinate of the top-left corner
    • width: Width of the bounding box
    • height: Height of the bounding box
  • value: Detected text
  • prob: Confidence score (0-1)

Project Structure

.
├── Dockerfile
├── ocr_server.py
├── README.md
└── sample_images/

How It Works

  1. The server uses EasyOCR to detect text in images
  2. Bounding box coordinates are converted to a structured format (x, y, width, height)
  3. Confidence scores are provided for each text detection
  4. Results are returned as JSON

The Docker image is optimized for CPU inference, making it suitable for deployment on systems without dedicated GPUs.

Supported Languages

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 codes

Configuration

The 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.py

The server will listen on the port specified by the PORT environment variable, or fall back to port 8000 if the variable is not set.

Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success
  • 400: 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"
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors