Skip to main content

Nkocr: The OCR tool for nutritional tables

Nkocr_logo

PyPI version License Python Test CodeQL

CodeFactor codecov Colab

Tweet

This is a module to make specifics OCRs at food products and nutritional tables.

Contents

📝 Prerequisites

As a prerequisite of this project, we have the tesseract library and OpenCV, so next we will install this preßsites.

Tesseract OCR

The installation of tesseract on the Linux system can be done in a few commands:

sudo apt install tesseract-ocr libtesseract-dev

And the same goes for macOS. There is a variation between MacPorts and Homebrew, but in this post I will only quote the version of Homebrew:

brew install tesseract

After performing the tesseract installation, it is possible to perform OCR in just one command, thus already extracting some words from the image.

OpenCV

The installation of opencv on the Linux system can be done in a command:

sudo apt install python3-opencv

And to macOS running the following command:

brew install opencv

⚙️ Installation

Now, assuming the prerequisites have already been installed, you're ready to install the Nkocr environment to modify, contribute and work!

But, if you just want to use the project, go to the usage part.

Pip

You can install the project requirements in a Python environment by running:

pip install -r requirements.txt --user

Conda

But if you are used to using a conda environment to keep everything organized, or if you want to test using it this time, feel free to run the following command and have a unique environment for Nkocr.

conda env create -f environment.yml

👨‍💻 Usage

To use this package, it's very easy, first you need to install it by running:

pip install nkocr --user

And after installing, you can import the packages in a Python script like the example below.

from nkocr import OcrTable, OcrProduct

Example

To make it even easier, below is an example of code snippet.

from nkocr import OcrTable

text = OcrTable("paste_image_url_here")
print(text) # or print(text.text)

ℹ️ Under the Hood

From now on we will be talking about a little more technical details of the library.

Changing Language

The default language is English, so depending on the text, it will not be possible to capture the desired words / phrases. Therefore, if you want to work with another language, you will need to make some changes inherent to the language that the algorithm executes.

The first thing is to download the desired language with tesseract support, and on Linux this can be done by running the following command: Don't forget to change <lang> with the desired language. If you would like more details, please feel free to access the tesseract documentation.

sudo apt install tesseract-ocr-<lang>

If you are a macOS user, your command will be a little different. You will need to run the following command, and don't worry about the language, after running this command you will have access to all languages.

brew install tesseract-lang

After downloading the support languages, to perform the translations in the desired language you will have to change the code in the ocr_product.py, ocr_table.py and auxiliary.py.

Operating Pipeline

The main algorithm was built working, mainly, with structures and methods of computer vision and digital image processing. The image below clearly depicts the line followed for the operational pipeline combinations.

Pipeline_Nkocr

🤝 Supporting

Many hours of hard work have gone into this project. Your support will be very appreciated!

Buy Me A Coffee

Metadata

Release files for nkocr 2.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nkocr 2.5.1
File Size Uploaded
nkocr-2.5.1.tar.gz 85.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for nkocr 2.5.1
File Interpreter ABI Platform
nkocr-2.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 85.0 MB

Release files / nkocr-2.5.1.tar.gz

Download URL nkocr-2.5.1.tar.gz
Size 85.0 MB
Tags Source
SHA-256 checksum
How to use checksums
5a759baecbb837e234301e66a533d7b21b2647e8cf34f8b91337956ec46d24d0
BLAKE2b-256 checksum
How to use checksums
d6c66e2589271a512c1b190952b8b810d351e8f415f9d7ee102530f9f0e677b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / nkocr-2.5.1-py3-none-any.whl

Download URL nkocr-2.5.1-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9af2aec5e63f848d65ec6d2d58b7a32bf584d96f1a341b4ca346edcbb51ec768
BLAKE2b-256 checksum
How to use checksums
a3e88946f98601965cf7d54b49aaae7fe9608d779920a307a78460d304f597c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

2.5.1 This release

2 release files

2.4.4

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.8.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page