My wife always wanted to have one feature in our digital picture frame: To know where a particular photo was taken.
When you have thousands of photos on your Raspberry Pi digital picture frame, you may not immediately remember every single image taken over many years from your far-away travels.
This is where the GPS data comes in handy. Every modern smartphone will record the geo-coordinates of where a picture has been taken. DSLR photographers can use a GPS module on their camera, which can record this data. And alternatively, you can add the location manually in post-processing software like Adobe Lightroom.
If you are unfamiliar with the image viewer Pi3D, please look at this article first.
How to extract the GPS data and turn it into places
Manuel described one way to show geolocation data in his article when he built his photo frame.
But as always, there are many ways to skin a cat.
Recently, Paddy, the author of Pi3D, the undisputed best image viewer for Raspberry Pi based digital picture frames, updated his PictureFrame2020 script to allow a much simpler way to show the GPS location of a photo.
The GPS data that is stored in a JPG file provides the longitude and latitude data. But this needs to be translated into places or towns and countries; a process called “reverse geocoding”.
You wouldn’t want to see “latitude 48.864716 and longitude 2.349014” on your display but expect it to be translated as “Avenue des Champs-Elysées, Paris, France.”
Luckily, many free services provide these reverse geocoding services. And with Geopy, there is a perfect Python client to connect to several popular geocoding web services.
Paddy used Nominatim in his Pi3D image viewer script, a tool to search Open Street Map (OSM) data by name and address and to generate addresses of OSM points.
For example, this service tells us that latitude 48.864716 and longitude 2.349014 is Paris and not Los Angeles.
The advantage of using Nominatim is that you don’t need to create an account with any user name and password hassle. It works right out of the box with any random user name.
Here is how you install it.
Installing the Geo extension of Pi3D
Make sure that you have the latest Pi3D version. You need at least Version 2.41.
To find out which version you have, enter in Terminal:
python3 -c 'import pi3d; print(pi3d.__version__)'
You can update with
sudo pip3 install pi3d --upgrade
To get the latest example files, PictureFrame2020.py, etc. enter
wget https://github.com/pi3d/pi3d_demos/archive/master.zip && unzip master.zip && mv pi3d_demos pi3d_demos_old && mv pi3d_demos-master pi3d_demos && rm master.zip
The latest version of Pi3D includes a new file called “PictureFrame2020geo.py”.
This file is a kind of subroutine of the main PictureFrame2020.py script so that the original script can be kept tidy. The PictureFrame2020config.py file also includes new geo settings.
The good thing is that if you don’t want the geoservice, it doesn’t make the installation of Pi3D any more complex. And if you do, there are a few easy settings to get it working in no time.
Start by installing Geopy on your Raspberry Pi.
sudo pip3 install geopy
If you get something like this in return, your installation will have been a success.
pi@raspberrypi:~ $ sudo pip3 install geopy Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting geopy Downloading https://files.pythonhosted.org/packages/07/e1/9c72de674d5c2b8fcb0738a5ceeb5424941fefa080bfe4e240d0bacb5a38/geopy-2.0.0-py3-none-any.whl (111kB) 100% |████████████████████████████████| 112kB 1.8MB/s Collecting geographiclib<2,>=1.49 (from geopy) Downloading https://files.pythonhosted.org/packages/8b/62/26ec95a98ba64299163199e95ad1b0e34ad3f4e176e221c40245f211e425/geographiclib-1.50-py3-none-any.whl Installing collected packages: geographiclib, geopy Successfully installed geographiclib-1.50 geopy-2.0.0 pi@raspberrypi:~ $
Next, open PictureFrame2020config.py.
Look for these lines
parse.add_argument( "--load_geoloc", default=False, type=str_to_bool, help="load geolocation code") parse.add_argument( "--geo_key", default="picture_frame_park_grange", help="set the Nominatem key - change to something unique to you")
Change the first line to default=”True” to activate Pi3D’s geo module.
parse.add_argument( "--load_geoloc", default=True, type=str_to_bool, help="load geolocation code")
Add a “unique key” in the next line in “default” to replace “picture_frame_park_grange”. You can use just about any word. Nominatem doesn’t require you to create an account but uses a unique identifier to prevent users from abusing a free service. If lots of people use the same string, then Nominatem might start restricting the queries, so put a word here that is not too commonplace. Pick the name of your dog or cat plus your postal code or any random funny name.
parse.add_argument( "--geo_key", default="name_of_your_dog_12345", help="change this to something unique to you")
Finally, you can define the location of the file that caches the reverse geodata for your images. The cache saves the location data for an image that has already been retrieved. This saves bandwidth and Nominatim server load. You can change it to another location to fit in with your filing system.
However, you will need to delete this file if you change the GPS information of any existing images, otherwise, the old information will still be shown. Just delete the file “PictureFrame2020gpsdata.txt”, it will be recreated automatically.
parse.add_argument( "--geo_path", default="/home/pi/PictureFrame2020gpsdata.txt", help="set the local file to store data from geopy - ignored if --load_geoloc is not true")
Changing the language of the Geo Information
The language of the places (e.g., countries) is based on your Raspberry Pi default language that you have specified in
in the “Localisation” section. So, if you want to change the language, go in there and select additional language sets. I would recommend using the “UTF8” variant of a language as this helps to display any special characters in your language properly, e.g., German Umlaute or French accents.
At the end of the selection, you will be asked to select your default locale. This will be the language to show e.g., “Österreich” instead of “Austria” in the address data.
To change the date format, have a look here.
Please note: In your home directory is a file called “gpsdata.txt”. This where the geocodes of all images are cached so that you don’t need to retrieve them again. When you change the language code, you must also delete this file. I will be recreated automatically with the new language settings. If you are curious, open “gpsdata.txt” and you can see all the geographic data that was retrieved for your photos.
Triggering the display of the geolocation automatically when images change
As described in this article, the display of the file name, the Exif date, or the location is either invoked whenever a new image fades in or is manually triggered by using an MQTT command.
If you want to show either information automatically, look for this line in the PictureFrame2020config.py script:
parse.add_argument( "--show_text", default="name", help="show text, include combination of words: name, date, location")
If you want to show the file name enter “name”, “date” shows the Exif date (if available, else the file date), and “location” – you guessed it – the place where the photo was taken. You can also enter a combined value like
parse.add_argument( "--show_text", default="date, location", help="show text, include combination of words: name, date, location")
to always show the date followed by the place.
In this line, you define the duration, i.e. how many seconds the information is displayed. The default is “10.0” seconds.
parse.add_argument("-s", "--show_text_tm", default=10.0, type=float, help="time to show text over the image")
Triggering the display of the geolocation on demand
You may not want any information to be overlaid permanently on your photos all the time. However, it’s actually quite intriguing to turn it on permanently for a while. Especially for events, it may be interesting for your guests to see where you have been. (Ok, that is a bit of bragging but you get the idea!)
But to trigger the text overlay display manually, this is how it works:
Pi3D contains extensive remote control capabilities via MQTT, which you can find in the main PictureFrame2020.py script below the headline
# set up MQTT listening
MQTT may be somewhat confusing initially, but once you understand the basic logic, you will see that it is very straightforward to use and yet very powerful.
I have written articles explaining each mode in the links above.
The MQTT messages that you need to know for the display of an information bar are:
client.subscribe("frame/text_on", qos=0) # toggle file name on and off. payload text show time in seconds client.subscribe("frame/date_on", qos=0) # toggle date (exif if avail else file) on and off. payload show time client.subscribe("frame/location_on", qos=0) # toggle location (if enabled) on and off. payload show time client.subscribe("frame/text_off", qos=0) # turn all name, date, location off client.subscribe("frame/text_refresh", qos=0) # restarts current slide showing text set above
I have covered the date and file name here. For location just send an MQTT with the topic “frame/location_on” and a payload of “10” for a ten-second display or whatever value you prefer.
You can toggle the display of the various items. To turn off the overlay of the location, just send another “frame/location_on”.
To turn off the information overlay completely, use “frame/text_off”.
And “frame/text_refresh” brings up the display again if you couldn’t read it before it disappeared.
By the way, even if you turn off the text overlay: When you pause, “PAUSED” is briefly displayed.
client.subscribe("frame/paused", qos=0) # payload on, yes, true pause, off, no, false un-pause. Anything toggle state
When everything works, you will see something like
What is really nice with the Nomination Geo Service that in conjunction with Open Street Map, a lot of additional information will show up. Stuff that volunteers from all over the world have entered, which has a connection with the place where you took your photo. The example above is from a place in New Zealand where a scene from a movie was filmed. The language of the places and the date were set to German in the Pi3D config file.
Please note: If no location is shown, then no valid Exif GPS data was found. If “no location found” is shown, it means that the Geoservice has no address, e.g. when you are flying or sailing across the ocean.
Please note: If the Exif data is not shown properly, then your Exif information may be corrupted. You can’t see this as the file opens and shows as normal. Out of 1,000 old photos, I had it in over 300 files, most of them older. What I did was to export them from Adobe Lightroom again, and then everything was clean. You can probably do the same with the photo software that you are using. You can verify the state of your Exif data with this simple script.
Please note: Reverse geocoding does not (yet) work with HEIC files.
I find the display of location data most interesting as it invokes even more memories in addition to seeing the photo. Yes, it does require that your photos are tagged but as most photos today are taken with a smartphone, the location is already included.
Thank you very much, Paddy, for yet another tremendous Pi3D feature!
Was this post helpful?
- Ask Siri about when a photo on your Raspberry Pi digital picture frame was taken
- How Victor built a WiFi photo frame with Pi3D which shows the location where the photo was taken (Geolocation)
- How to trigger a Home Assistant script through Alexa and make your Raspberry Pi picture frame do (just about) anything
- The HEIC/HEIF photo format now works with the Raspberry Pi Pi3D digital picture frame image viewer