allow overriding DPI

pull/33/head
Konstantin Baierer 4 years ago
parent 3e4ac11347
commit 1715f0d8b3

@ -92,7 +92,8 @@ class Eynollah:
curved_line=False, curved_line=False,
full_layout=False, full_layout=False,
allow_scaling=False, allow_scaling=False,
headers_off=False headers_off=False,
override_dpi=None,
): ):
self.image_filename = image_filename self.image_filename = image_filename
self.dir_out = dir_out self.dir_out = dir_out
@ -102,6 +103,7 @@ class Eynollah:
self.full_layout = full_layout self.full_layout = full_layout
self.allow_scaling = allow_scaling self.allow_scaling = allow_scaling
self.headers_off = headers_off self.headers_off = headers_off
self.override_dpi = override_dpi
if not self.image_filename_stem: if not self.image_filename_stem:
self.image_filename_stem = Path(Path(image_filename).name).stem self.image_filename_stem = Path(Path(image_filename).name).stem
self.plotter = None if not enable_plotting else EynollahPlotter( self.plotter = None if not enable_plotting else EynollahPlotter(
@ -346,10 +348,9 @@ class Eynollah:
def resize_and_enhance_image_with_column_classifier(self): def resize_and_enhance_image_with_column_classifier(self):
self.logger.debug("enter resize_and_enhance_image_with_column_classifier") self.logger.debug("enter resize_and_enhance_image_with_column_classifier")
try: if self.override_dpi:
return self.override_dpi
dpi = check_dpi(self.image_filename) dpi = check_dpi(self.image_filename)
except:
dpi = 230
self.logger.info("Detected %s DPI", dpi) self.logger.info("Detected %s DPI", dpi)
img = self.imread() img = self.imread()

@ -15,10 +15,12 @@ def pil2cv(img):
return cvtColor(pil_as_np_array, color_conversion) return cvtColor(pil_as_np_array, color_conversion)
def check_dpi(image_filename): def check_dpi(image_filename):
try:
exif = OcrdExif(Image.open(image_filename)) exif = OcrdExif(Image.open(image_filename))
print(exif.to_xml())
resolution = exif.resolution resolution = exif.resolution
if exif.resolutionUnit == 'cm': if exif.resolutionUnit == 'cm':
resolution /= 2.54 resolution /= 2.54
return int(resolution) return int(resolution)
except:
return 230

Loading…
Cancel
Save