Close

Rev 2 - Basic Rotation using EXIF tags

A project log for MiFrame - Yet Another (Raspberry) Pi Smart Frame

MiFrame is a Python Smart Photo Frame application. Supports sharing database across multiple frames, marking favorites, thumbs up etc

tklenketklenke 03/02/2017 at 05:200 Comments

In Rev 1, I used the image width and height that ImageTk returned to determine whether it was a portrait or landscape photo. If width was the larger = landscape, else = portrait. Once I knew it was portrait, then I knew to scale the image so that the height matched the frame height. If it was landscape, then I scaled using the width as the constraint.

Using this method works great for landscape photos. For portrait photos, the initial success rate was probably about 1/3. I'd walk by the kitchen table to see my wife smiling with her head tilted over on it's side looking at a photo rotated 90 degrees from where it should be. Not bad, but not good enough.

My initial thought was, hey, let's use OpenCV to look at the photo and let it decide whether it's portrait or landscape. Cool, google... starting recipe .... http://stuporglue.org/automatically-orient-scanned-photos-correctly-with-opencv/

But then, I thought...why do most of the image viewers show the image in the correct orientation? Certainly they aren't using image processing...it must be in the jpg file. Google...EXIF tags...humm, is there a python EXIF tag module, yes, sweet. https://www.blog.pythonlibrary.org/2010/03/28/getting-photo-metadata-exif-using-python/

EXIF gives an orientation field. It's a numeric value 1-8. Here's a quick explanation http://jpegclub.org/exif_orientation.html

Version 2 uses EXIF tags to orient the photos. I may still add OpenCV for images that don't have an orientation EXIF tag, but for now I've gone from 2 of 3 portrait photos being incorrectly displayed to 9 out 10 being good. Big improvement for not much CPU cycles.


Discussions