{"id":20448526,"url":"https://github.com/amajji/crop-and-ocr-documents-and-deployment-using-fastapi-and-docker","last_synced_at":"2025-09-12T05:45:16.411Z","repository":{"id":133033577,"uuid":"533308121","full_name":"amajji/Crop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER","owner":"amajji","description":"Crop and OCR documents and deployment using FastAPI and DOCKER","archived":false,"fork":false,"pushed_at":"2023-04-21T13:27:57.000Z","size":23385,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T18:50:36.355Z","etag":null,"topics":["docker","fastapi","ocr","ocr-python","ocr-text-reader","opencv","opencv-python","web"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amajji.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-06T12:15:43.000Z","updated_at":"2025-03-10T08:42:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"c827a029-952a-4908-97c0-71ba62ff41b3","html_url":"https://github.com/amajji/Crop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/amajji/Crop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amajji%2FCrop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amajji%2FCrop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amajji%2FCrop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amajji%2FCrop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amajji","download_url":"https://codeload.github.com/amajji/Crop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amajji%2FCrop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274760835,"owners_count":25344264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","fastapi","ocr","ocr-python","ocr-text-reader","opencv","opencv-python","web"],"created_at":"2024-11-15T10:35:31.651Z","updated_at":"2025-09-12T05:45:16.362Z","avatar_url":"https://github.com/amajji.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Crop-and-OCR-documents-and-deployment-using-FastAPI-and-DOCKER-\n\nData scientist | [Anass MAJJI](https://www.linkedin.com/in/anass-majji-729773157/)\n***\n\n## :monocle_face: Description\nThis project aims to implement two algorithms to crop and extract text fields from any document, and deploy in a web app using FastAPI and DOCKER.\n\n- The first technique is a SIFT model (scale-invariant feature transform), a model used to identify similar elements between different images.\n\n\n- The second is a model based on Kmeans for clusturing to segment the image into many blocs/objects, and the openCV packages to detect the countour's document and rotate it based on its letter orientation. \n\n \u003c/br\u003e\n\n\n## :rocket: Repository Structure\nThe repository contains the following files \u0026 directories:\n- **docker directory:** : The folder contains the webapp files as well as the dockerfile and requirements.txt needed to deploy with Docker. The web application was developed using FastAPI for the Back-End, and HTML/CSS/Javascript code for the Front-End.\n\n\n- **crop_ocr_documents.ipynb :** Is the script where we detail the two techniques for cropping and extracting text fields from documents\n\n- **images directory:** The folder contains the images used on the notebook.\n\n\n\n## :collision: Demonstration \n\nTo launch the deployment of the webapp with docker, type the following commands : \n\n\n - **docker build -t webapp_ocr .**  : to build the docker image\n\n - **docker run -p 8000:80 webapp_ocr:latest** : to launch the container based on our image\n\n If we visit http://127.0.0.1:8000/, we'll get our webapp deployed.\n\nBelow the demonstration:\n\n![](images/gif.gif)\n\n\nIn order to track the webapp's logs in the docker container, type the following command to explore the container state: \n\n - **docker exec -t -i ID_CONTAINER /bin/bash**\n\nThen logs are stored in the **logfile.log** as shown below : \n\u003cp float=\"left\"\u003e\n  \u003cimg src=\"images/logs.png\" width=\"600\" /\u003e\n\u003c/p\u003e\n\n\n\n## :chart_with_upwards_trend: Performance \u0026 results\n\n\n\nwe tested the models on 300 tax notices. The SIFT method does not crop all documents, especially when the scans are not in a good quality, while the second script which is based on the kmeans algorithm crops and extracts the text fields from any document. \n\n\n\u003cp float=\"left\"\u003e\n  \u003cimg src=\"images/1__1_v2.png\" width=\"350\" /\u003e\n    \u003cimg src=\"images/fleche_1.png\" width=\"100\" /\u003e \n  \u003cimg src=\"images/corners_v2.png\" width=\"350\" /\u003e \n\u003c/p\u003e\n\nAfter cropping the document, we use Pytesseract to recognize and read the text embedded in the scan, means: we convert a scan document which is an image to text file. We use then Regex to extract text fields from the document.\n\n\u003cp float=\"left\"\u003e\n  \u003cimg src=\"images/word.png\" width=\"200\" /\u003e\n  \u003cimg src=\"images/fleche_1.png\" width=\"50\" /\u003e \n  \u003cimg src=\"images/regex.png\" width=\"250\" /\u003e \n  \u003cimg src=\"images/fleche_1.png\" width=\"50\" /\u003e \n  \u003cimg src=\"images/excel.png\" width=\"150\" /\u003e \n\u003c/p\u003e\n\n\n---\n## :mailbox_closed: Contact\nFor any information, feedback or questions, please [contact me][anass-email]\n\n\n\n\n\n[anass-email]: mailto:anassmajji34@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famajji%2Fcrop-and-ocr-documents-and-deployment-using-fastapi-and-docker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famajji%2Fcrop-and-ocr-documents-and-deployment-using-fastapi-and-docker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famajji%2Fcrop-and-ocr-documents-and-deployment-using-fastapi-and-docker/lists"}