Package: robotframework-ocrlibrary
Robot Framework OCR LibraryA robot framework library that is capable of processing images, validating text, and locating specified text by coordinates within images.Keyword DocumentationYou can find thekeyword documentation here.Installation and UsageOCRLibrary can be run on Python 3.6, 3.7, 3.8, and 3.9.To install, runpip install robotframework-ocrlibraryDependenciesOCRLibrary uses two dependencies downloadable through the pip package manager, opencv-python and pytesseract. As well as Tesseract OCR.TesseractOCRLibrary requires Google's Tesseract OCR software.LinuxTo install tesseract on Linux, runsudo apt install tesseract-ocrMacOSTo install tesseract on MacOS, runbrew install tesseractWindowsTo install tesseract on Windows, download one of the installers fromUB-Mannhiem/tesseractOnce installed add the path to the tesseract folder (ex: C:\User\Program/ Files\tesseract) to your environment variables.Download verificationRun the commandtesseract -vto confirm that tesseract was downloaded successfully.More installation instructionsFor more detailed installation instructions of tesseract please seethe following installation guide.OpenCV PythonTo install opencv-python, runpip install opencv-python.
Please seeopencv-python's installation and usage sectionfor more information.PytesseractTo install pytesseract, runpip install pytesseract.
Please seepytesseracts installation sectionfor more information.UsageOnce OCRLibrary is installed, along with its dependencies, addLibrary    OCRLibraryto your robot file to use.Installing LanguagesYou can see which languages are available by runningtesseract --list-langs. You can do the following to install more languages.Here is a list of supported languages, language codes and tessdata files.LinuxTo install all languages on Linux, runsudo apt install tesseract-ocr-all.To install a specific language on Linux, runsudo apt install tesseract-ocr-<lang>. Where<lang>is the language code.MacOSTo install all language on MacOS, runbrew install tesseract-lang.WindowsTo download a language on Windows, you must install the trained model for your desired language.This repo has many language models to download. Here aremore tessdata files. Once downloaded, place the trained model in the tessdata directory (i.e. where the tesseract.exe is located).Custom configurations for reading imagesYou can add any combination of the following to thepyt_confstring argument.Page segmentation modesPage segmentation modes provide different ways a page of text can be analyzed. Here is a list of supported page segmentation modes:ModeDescription0Origentation and script detection only.1Automatic page segmentation with OSD.2Automatic page segmentation, but no OSD, or OCR.3Fully automatic page segmentation, but no OSD. (Default)4Assume a single column of text of variable sizes.5Assume a single uniform block of vertically aligned text.6Assume a single uniform block of text.7Treat the image as a single text line.8Treat the image as a single word.9Treat the image as a single word in a circle.10Treat the image as a single character.11Sparse text. Find as muuch text as possible in no particular order.12Sparse text with OSD.13Raw line. Treat the image as a single text line, by passing hacks that are Tesseract-specific.To change your page segmentation mode, add--psm <mode>to your custom configuration string.OCR Engine ModesSelect the OCR engine modes to be used by pytesseract:ModeDescription0Legacy engine only.1Neural nets LSTM engine only.2Legacy + LSTM engines.3Default, based on what is available.To change your ocr engine mode, add--oem <mode>to your custom configuration string.Whitelisting CharactersThis configuration specifies which characters to detect.
Add the characters you want to detect to the string:-c tessedit_char_whitelist=.
An example to only detect lowercase letters:-c tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyzBlacklisting CharactersOpposite to whitelisting characters, this configurations lets you specify which characters to not detect.
Add the characters you want to not detect to the string:-c tessedit_char_blacklist=An example to not detect special characters:-c tessedit_char_whitelist=!@#$%^&*()Other ConfigurationsVisit this sitefor a complete list of Tesseract configuration parameters.Example of custom configuration string usageIn this example, the content will be returned from the processed image using page segmentation mode 6 and it will ignore all numbers.${content}=    Get Image Content   ${processed_image}  --psm 6 -c tessedit_char_blacklist=0123456789Image processing using OpenCVPlease see any of the following links for more information on image processing using OpenCV:Changing Colour SpacesThresholdingSmoothing ImagesMorphological TransformationsContributingThank you for thinking of contributing to the robotframework-ocrlibrary!When contributing please adhere to the following.If you find a bug, please submit an issue.If you want to fix something or improve upon something, fork the repo, and create a new branch.
Once you have made the changes and have written unit tests or updated the regression tests (please use pythons Unittest when testing), make a pull request.Please put the files in the appropriate directories with the appropriate names. The image processing features fall under any ofthese categories, please name the file to resemble that category (seeexisting filesfor examples), or add to an existing file.