Python for Great Circle Projections


For an internal project at my company, I was asked to write code to draw great circles projected on to an equirectangular plane. Why this is useful I will discuss a little later, but first, what exactly are great circles?

Great Circles

great circle on Earth

A great circle is the largest circle that can be drawn on any given sphere. Every circle in Euclidean 3-space is a great circle of exactly one sphere. For most pairs of points on the surface of a sphere there is a unique great circle through the two points.

-wikipedia

When dealing with 360 video, the idea of stabilising the video becomes a much more interesting question. For normal videos, you can use optical flow to determine jitters and correct for that, but with 360 video (projected on a flat equirectangular plane), this does not necessarily work since optical flow would give very different values in different regions.

360 Optical Flow - 1

360 Optical Flow - 2

note how in the above two photos taken a second apart the trees on the right and left move in different directions while the middle stays the same.

This makes it very hard to use optical flow to figure out how to stabilise the video. One remarkable feature in 360 videos, however, is how the horizon is captured. Take a look at the photos below:

360 Optical Flow - 3

360 Optical Flow - 4

note how the horizon curves as the plane turns

As can be seen above, as the plane takes a turn, the horizon curves. Luckily, this entire curve is deterministic on two values:

  • the pitch of the plane/camera
  • the roll of the plane/camera

the horizon curve is independent of the yaw of the plane.

roll, pitch, yaw

Now this is where great circles come in. Great circles look like, well, circles on a sphere - but project them on an equirectangular surface, and voila! You get yourself nice curve just like the horizon ones in the photos above.

This meant that we could use the roll and pitch values to deterministically generate curves and then compare them to the horizons in the video to see how much the camera was changing orientation. Once we have that, we could use the information to stabilise the video by counteracting the roll and pitch of the camera!

Let’s take a look at the code to plot the curves in the next post.

-Taha


comments powered by Disqus