QGIS processing algorithm which recognizes text from raster images inside input polygon features and saves as attribute value of output layer.
PW_OCR_ADVENCED script processes in different way than PW_OCR_ADVANCED. Check specifications of both scripts to choose better one for your applications.
If usage of the script leads to a scientific publication, please acknowledge this fact by citing:
Graszka, O. (2021). Automatyzacja procesu rozpoznawania i weryfikacji nazw geograficznych ze źródeł historycznych na przykładzie Słownika geograficznego Królestwa Polskiego. W T. Epsztein (red.), Od Słownika geograficznego Królestwa Polskiego do map topograficznych Wojskowego Instytutu Geograficznego (s. 23–32).
PW_OCR script usues Pytesseract library and requires its installation. After installation you have to update path to your Tesseract directory at the beginning of the script.
// path to your tesseract installation directory.
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
You may set Pytesseract configuration (page segmentation mode and OCR engine model) using comboboxes of script graphical interface, but if you want to use language other than polish, you have to edit line below in the code:
text = pytesseract.image_to_string(img, lang='pol', config=self.config)
This algorithm iterates over all input polygon features and processes them according to this scheme:
- Exporting feature as separate shapefile in temporary file location.
- Clipping raster overlaying the feature to the already made shapefile object boundaries and saving it into temporary file location (using GDAL library).
- Regonizing text on the clipped raster image (Pytesseract library).
- Adding recognized text as attribute value to output feature field.
Text output field
Run for all raster layers
Input raster layer
In case of multiband raster images, the only first band will be used.
Page Segmentation Mode
OCR Engine Model
Remove comma
Temporary files location
Output layer