check_dpi: use OcrdExif instead identify callout
parent
0a92543245
commit
8c603ae16d
@ -0,0 +1,24 @@
|
|||||||
|
from PIL import Image
|
||||||
|
import numpy as np
|
||||||
|
from ocrd_models import OcrdExif
|
||||||
|
from cv2 import COLOR_GRAY2BGR, COLOR_RGB2BGR, cvtColor, imread
|
||||||
|
|
||||||
|
# from sbb_binarization
|
||||||
|
|
||||||
|
def cv2pil(img):
|
||||||
|
return Image.fromarray(img.astype('uint8'))
|
||||||
|
|
||||||
|
def pil2cv(img):
|
||||||
|
# from ocrd/workspace.py
|
||||||
|
color_conversion = COLOR_GRAY2BGR if img.mode in ('1', 'L') else COLOR_RGB2BGR
|
||||||
|
pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img)
|
||||||
|
return cvtColor(pil_as_np_array, color_conversion)
|
||||||
|
|
||||||
|
def check_dpi(image_filename):
|
||||||
|
exif = OcrdExif(Image.open(image_filename))
|
||||||
|
print(exif.to_xml())
|
||||||
|
resolution = exif.resolution
|
||||||
|
if exif.resolutionUnit == 'cm':
|
||||||
|
resolution /= 2.54
|
||||||
|
return int(resolution)
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from sbb_newspapers_org_image.utils.pil_cv2 import check_dpi
|
||||||
|
from tests.base import main
|
||||||
|
|
||||||
|
def test_dpi():
|
||||||
|
fpath = Path(__file__).parent.joinpath('resources', 'kant_aufklaerung_1784_0020.tif')
|
||||||
|
assert 300 == check_dpi(str(fpath))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(__file__)
|
Loading…
Reference in New Issue