Coder Social home page Coder Social logo

visionflask's Introduction

OCR Text Recognition with Flask and macOS Vision Framework

This project is a Flask-based web application that allows users to upload images and perform Optical Character Recognition (OCR) using the macOS Vision framework. The recognized text and its bounding boxes are returned as JSON and also saved as a .json file on the server.

Features

  • Upload images in png, jpg, or jpeg formats.
  • Perform text recognition using macOS Vision framework.
  • Save the uploaded image and recognition results with unique identifiers.
  • Return recognition results as JSON.

Requirements

  • macOS with Python and the necessary macOS frameworks (Cocoa, Quartz, Vision).
  • Flask for the web server.
  • Werkzeug for secure file handling.

Installation

  1. Clone the repository:

    git clone https://github.com/zibo-chen/VisionFlask.git
    cd VisionFlask
  2. Create a virtual environment and activate it:

    python3 -m venv venv
    source venv/bin/activate
  3. Install the required Python packages:

    pip install -r requirements.txt
  4. Ensure you have the necessary macOS frameworks:

    The project uses Cocoa, Quartz, and Vision frameworks which are available on macOS. Ensure you have these installed and accessible in your Python environment.

Usage

  1. Run the Flask application:

    python app.py
  2. Upload an image:

    Use a tool like curl or Postman to upload an image to the /ocr endpoint.

    curl -X POST -F "file=@path_to_your_image.png" http://localhost:5001/ocr
  3. View the results:

    The response will be a JSON object containing the recognized text and their bounding boxes. The uploaded image and the recognition results will be saved in the uploads directory with unique identifiers.

Project Structure

  • app.py: The main Flask application file.
  • utils/text_recognition.py: Contains the TextRecognizer class that uses macOS Vision framework for text recognition.
  • uploads/: Directory where uploaded images and recognition results are saved.

Example

Here is an example of the JSON response from the /ocr endpoint:

{
    "log_id": "12345678901234567890",
    "words_result_num": 2,
    "words_result": [
        {
            "words": "Hello",
            "location": {
                "top": 0.1,
                "left": 0.2,
                "width": 0.3,
                "height": 0.4
            }
        },
        {
            "words": "World",
            "location": {
                "top": 0.5,
                "left": 0.6,
                "width": 0.7,
                "height": 0.8
            }
        }
    ]
}

visionflask's People

Contributors

zibo-chen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.