Skip to content

A Flask-based API that handles image uploads and processes them using EasyOCR to extract text from images, specifically designed for scanning medicine-related content.

Notifications You must be signed in to change notification settings

lancedalanon/medicine-ocr-flask-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask Backend for Medicine OCR React Native Application

Flask Python EasyOCR Pillow dotenv

This backend application is built using Flask, a lightweight Python web framework, and serves as the backend for the Medicine OCR React Native application. The backend provides an API for uploading images and extracting text from them using EasyOCR, which is especially useful for scanning and processing text from medicine labels, prescriptions, and packaging.

Installation

  1. Clone the repository:

    git clone https://github.com/lancedalanon/medicine-ocr-mobile.git
  2. Install the required dependencies:

    pip install -r requirements.txt
  3. Create a .env file to store the environment variables (e.g., API key):

    API_KEY=your_api_key_here
  4. Run the application:

    python app.py

Routes

GET /ping

A health check route to ensure the server is running.

Response:

{
  "message": "Server is up!",
  "data": null
}
POST /process-image
This route accepts an image file, processes it using EasyOCR, and returns the extracted text.

Request Body:

image: (Required) Image file to be processed.
Response:

json
{
  "message": "Image processed successfully!",
  "data": "Extracted text from the image"
}

If an error occurs:

{
  "message": "Error processing the image.",
  "data": "Error details"
}

Key Features

API Key Authentication: The /process-image route is protected by an API key. You must provide the correct API key in the request header X-API-KEY for access.

Image Processing with OCR: The application uses EasyOCR to extract text from images. It supports common image formats like PNG, JPG, and JPEG.

Environment Variables: The application uses a .env file to store configuration settings like the API key.

Concurrency: The application uses Python's ThreadPoolExecutor to process multiple images concurrently for optimized performance.

Example Usage

To test the server, you can use Postman or curl:

Ping the Server

curl http://127.0.0.1:5000/ping
Process an Image
bash
curl -X POST http://127.0.0.1:5000/process-image \
  -H "X-API-KEY: your_api_key_here" \
  -F "image=@path_to_your_image.jpg"

Error Handling

The application provides detailed error messages in case of failure, such as:

Missing or invalid API key Invalid file format OCR processing errors General server errors

License

This project is licensed under the MIT License.

About

A Flask-based API that handles image uploads and processes them using EasyOCR to extract text from images, specifically designed for scanning medicine-related content.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages