Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_page_seg_mode(self):
"""Test SetPageSegMode and GetPageSegMode."""
self._api.SetPageSegMode(tesserocr.PSM.SINGLE_WORD)
self.assertEqual(self._api.GetPageSegMode(), tesserocr.PSM.SINGLE_WORD)
self._api.SetPageSegMode(tesserocr.PSM.AUTO)
self.assertEqual(self._api.GetPageSegMode(), tesserocr.PSM.AUTO)
def test_page_seg_mode(self):
"""Test SetPageSegMode and GetPageSegMode."""
self._api.SetPageSegMode(tesserocr.PSM.SINGLE_WORD)
self.assertEqual(self._api.GetPageSegMode(), tesserocr.PSM.SINGLE_WORD)
self._api.SetPageSegMode(tesserocr.PSM.AUTO)
self.assertEqual(self._api.GetPageSegMode(), tesserocr.PSM.AUTO)
dpi = self.parameter['dpi']
LOG.info("Page '%s' images will use %d DPI from parameter override", page_id, dpi)
elif page_image_info.resolution != 1:
dpi = page_image_info.resolution
if page_image_info.resolutionUnit == 'cm':
dpi = round(dpi * 2.54)
LOG.info("Page '%s' images will use %d DPI from image meta-data", page_id, dpi)
else:
dpi = 0
LOG.info("Page '%s' images will use DPI estimated from segmentation", page_id)
if dpi:
tessapi.SetVariable('user_defined_dpi', str(dpi))
LOG.info("Detecting regions in page '%s'", page_id)
tessapi.SetImage(page_image) # is already cropped to Border
tessapi.SetPageSegMode(PSM.SPARSE_TEXT if self.parameter['sparse_text'] else PSM.AUTO)
# detect the region segments and types:
layout = tessapi.AnalyseLayout()
self._process_page(layout, page, page_image, page_coords, input_file.pageId)
# Use input_file's basename for the new file -
# this way the files retain the same basenames:
file_id = input_file.ID.replace(self.input_file_grp, self.output_file_grp)
if file_id == input_file.ID:
file_id = concat_padded(self.output_file_grp, n)
self.workspace.add_file(
ID=file_id,
file_grp=self.output_file_grp,
pageId=input_file.pageId,
mimetype=MIMETYPE_PAGE,
local_filename=os.path.join(self.output_file_grp,