Introduction: Mapping Cities Around the World

Picture of Mapping Cities Around the World

The idea for this project came to me when I was flying in the plane and thinking that I would be curious to know what are the cities I could see if I would go in the direction I am looking at. Not long ago before that I found a magnetometer sensor and was puzzling on what are the things I could build with it.

Step 1: ​The Setup

Picture of ​The Setup

These are the things I have used:

I have attached the camera and the compass sensor to the a circle that I cut out of the plywood. Making sure that my compass sensor roughly points at the center of the camera. My original idea was to have the whole setup attached to the servo motor but the motor broke down unexpectedly and I decided to continue the project by rotating the camera and compass by hand.

Step 2: Calibrating the Camera

Picture of Calibrating the Camera

For this project to work I needed to know how wide is the horizontal angle that my camera is able to see. The compass sensor would only tell me the direction only of the center of the camera. However, there are likely to be several cities visible in the same image. Once I know the horizontal angle of the camera, I can work out the angle to every pixel in the image and that would allow me to plot the cities.

I learned that camera calibration would allow me to get the viewing angle of the camera. This is how you do the calibration - you take photos of a chessboard and then run a Python OpenCV script to get the parameters of your camera. Here is how I have done it:

Step 3: Working Out City Positions

Picture of Working Out City Positions

First, I got the the list with longitude and latitude for each city. My next task was to find out the degrees from north where a given city would be given my current coordinates - what I needed is called bearing and there is a well-known formula for calculating the bearing given two coordinates. I have converted this formula into a Python script that I ran for each city. Once I had the data, I uploaded it to a local Mongo database to make it easier for me to query when I will plot the cities on the photo.

Step 4: Plotting Cities

Picture of Plotting Cities

To continue I need to take several photos while at the same time recording compass sensor readings. I do this by running two Arduino sketches one after another - first, I get the sensor readings and then I run another sketch to take photos. I rotate the camera and take as many pictures as I can so that I have a panorama later on.

At this point I know the viewing angle of my camera and the degrees from the north for each city given my current position. The next step is to visualize this data on a photo. Recall that the images I originally take with the camera are not perfect - I can improve them by using the camera calibration I have done previously.

Once I have the undistorted photos and the compass readings for each of them, I am ready to start plotting the cities. Here is the Python script that I have used. It does several things at the same time:

  • get all the cities that are within the camera's viewing angle
  • given the city degrees from north, calculate it's location on the photo
  • append photos to each other to create panorama image
  • add Google Maps at the bottom of each photo

Comments

Swansong (author)2017-07-23

This would be a fun setup to use in a geography class :)

About This Instructable

685views

12favorites

License:

Bio: I work as a software engineer and build projects with Intel Galileo board. I enjoy building things - be it electronics projects or things made out ... More »
More by Evgeny Arbatov:Mapping Cities Around the World
Add instructable to: