Go program finds photos with nearby GPS coordinates
Two Libraries for One, Hallelujah!
On GitHub, several libraries for reading Exif metadata from JPG photos vie for the favor of Go programmers. The most handy package I found was goexif2
, which doesn't freak programmers out with thousands of options, but uses Decode()
to analyze an image and returns the longitude and latitude as floating points with LatLong()
. The project by GitHub user xor-gate is no longer under development according to the readme, but it still worked perfectly for the given task.
If you are looking for enhancements, you will find about a dozen forks, but deciding on a specific one is like tossing a coin. I found the original is good enough, and it can be installed in the usual style for Go:
go get github.com/xor-gate/goexif2/exif
Following which, programs can utilize its functions (e.g., by lines 5 and 83 in Listing 1).
The GeoPos()
function from line 76 expects an image path as a string and returns two floats and an error value to the caller. First it opens the image file for reading, interprets the JPEG data with Decode()
, then uses LatLong()
to read the GPS Latitude
and Longitude
Exif tags, analyzes their angular minutes and seconds, and converts them into floating-point values.
golang-geo
was selected as the library featuring geometry functions for determining the distance between two locations. Line 4 adds it to the program under the geo
nick; the installation again needs to be completed up front – as shown above – with go get
.
Distance on a Great Circle
The programming logic as of line 63 determines the distance between the currently examined image and the reference shot. Using longitude and latitude pairs, it calls NewPoint()
to fill a Go structure for golang-geo
and then calls the GreatCircleDistance()
function with the start point p1
and the end point p2
. The distance between the two points in kilometers is returned as a floating-point number. If it is above the maximum distance of 100 meters (0.1
kilometers, or about 100 yards) specified in line 12, the return
statement in line 68 ignores the image; otherwise, lines 71 and 72 output the name of the photo file and its offset to the reference image.
While searching for photos of the now closed restaurant mentioned at the beginning, the algorithm actually discovered something interesting. I had passed in a reference photo of the restaurant's menu, shot recently (Figure 3), as a salt. The search came back with a photo of a wooden table, showing empty beer and wine glasses, no doubt at the same restaurant, after the waiter had brought the bill in a clean water glass, as was the custom at this place (Figure 4). Eureka, what a historic moment!
Big AI Brother
Imagine the possibilities if the GPS data of a photo collection are available. An AI program using the nearest neighbor method could, for example, form clusters of the snapshot locations – as already explained in a previous issue [5] – and thus determine the most often frequented locations of the mobile phone owner. If you think about it, it's downright scary! But social media companies, as you know, live off it to keep the lights on.
Infos
- Mitnick, Kevin. The Art of Invisibility. Little, Brown and Company, 2017: https://www.amazon.com/Art-Invisibility-Worlds-Teaches-Brother/dp/0316380504
- Orthodrome: https://en.wikipedia.org/wiki/Great-circle_distance
- golang-geo, a library for calculating distances between geographical points: https://www.github.com/kellydunn/golang-geo
- Listings for this article: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/225/
- "Calculating Clusters with AI Methods" by Mike Schilli, Linux Magazine, issue 145, December 2012, p. 62
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs