Package: nkocr
This is a module to make specifics OCRs at food products and nutritional tables.ContentsPrerequisitesTesseract OCROpenCVInstallationPipCondaUsageExampleUnder the HoodChoosing the LanguagePipelineSupporting📝 PrerequisitesAs a prerequisite of this project, we have thetesseract libraryandOpenCV, so next we will install this preßsites.Tesseract OCRThe installation of tesseract on theLinuxsystem can be done in a few commands:$sudoaptinstalltesseract-ocrlibtesseract-devAnd the same goes formacOS. There is a variation between MacPorts and Homebrew, but in this post I will only quote the version of Homebrew:$ brew install tesseractAfter performing the tesseract installation, it is possible to perform OCR in just one command, thus already extracting some words from the image.OpenCVThe installation of opencv on theLinuxsystem can be done in a command:$sudoaptinstallpython3-opencvAnd tomacOSrunning the following command:$brewinstallopencv⚙️ InstallationNow, 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 theusagepart.PipYou can install the project requirements in a Python environment by running:$pipinstall-rrequirements.txt--userCondaBut 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.$condaenvcreate-fenvironment.yml👨‍💻 UsageTo use this package, it's very easy, first you need to install it by running:pipinstallnkocr--userAnd after installing, you can import the packages in a Python script like the example below.fromnkocrimportOcrTable,OcrProductExampleTo make it even easier, below is an example of code snippet.fromnkocrimportOcrTabletext=OcrTable("paste_image_url_here")print(text)# or print(text.text)ℹ️ Under the HoodFrom now on we will be talking about a little more technical details of the library.Changing LanguageThe 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 thetesseract documentation.$sudoaptinstalltesseract-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.$brewinstalltesseract-langAfter downloading the support languages, to perform the translations in the desired language you will have to change the code in theocr_product.py,ocr_table.pyandauxiliary.py.Operating PipelineThe 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.🤝 SupportingMany hours of hard work have gone into this project. Your support will be very appreciated!