core
core copied to clipboard
OcrdExif / page_from_image: show/use orientation
I don't know how realistic this is for OCR-D data providers: What if the original images are not oriented upright / positive, and the imaging system already knows about this and uses the proper meta-data (via EXIF tag 0x0112 'Orientation')?
IMHO we should at least have an orientation member in OcrdExif.
# somewhere in OcrdExif:
# PIL.ExifTags.TAGS[0x0112] == 'Orientation'
ornt = img.getexif().get(0x0112)
ops = {
0: [],
1: [Image.FLIP_LEFT_RIGHT],
2: [Image.ROTATE_180],
3: [Image.FLIP_TOP_BOTTOM],
4: [Image.FLIP_LEFT_RIGHT, Image.ROTATE_90],
5: [Image.ROTATE_270],
6: [Image.FLIP_TOP_BOTTOM, Image.ROTATE_90],
7: [Image.ROTATE_90]
}
Further, I suggest making use of this in ocrd_modelfactory.page_from_image by annotating the orientation value as /PcGts/Page/@orientation accordingly. (I don't know what to do about flip operations though. Perhaps it's best to provide a normalized AlternativeImage right away. But our @comments conventions only have rotated-90 / rotated-180 / rotated-270, no reflected-h / reflected-v...)
Currently this gets ignored and if you're lucky you have ocrd-tesserocr-deskew in your workflow and it recognizes the angle correctly. (But again, Tesseract cannot detect reflection, only rotation.)
Alternatively, one could just mogrify -auto-orient image using ImageMagick before import...