Dewarping 360° images from the Pi camera board

Katherine Scott, newly equipped with a Raspberry Pi camera board, was looking for an image processing challenge. She realised she had an unused panoramic lens for an iPhone rolling around in a drawer somewhere at home, and got to work with the silly putty and cardboard to hook it up to the camera board.

Since my RPI camera module is just loose, and not mounted to anything, I needed a non-destructive and quick way to attach the lens to the camera. I created three cardboard shims using my pocket knife, one that fit snugly to the camera, one that fit snugly to the protrusion on the lens, and one to space the two parts out. I used silly putty to “glue” the boards together while allowing me to slide them around to get the alignment just right. Silly putty works great for this as it is non-conductive and easy to pick out the RPI camera board without breaking it. Also cleans up fairly easily.

The raw output from a lens like this gives you a doughnut-shaped image and a lot of surrounding cruft – Katherine uploaded some unmanipulated footage from the camera to YouTube to demonstrate what she had to work with.

Katherine’s job was to cut and unfold that doughnut, until she had a dewarped it into a recognisable rectangular image. To do this, she needed to understand where the centre of the doughnut was, what the radius of its hole was, and what the radius of the doughnut itself was. This information meant she’d be able to be able to map all the points in the image, and then translate them to a rectangle instead of a torus. Here are her notebook calculations:

Katherine coded all this in Python and has made it available for you to play with on GitHub. The results:

You can read much more, including a first draft of the dewarping code, Katherine’s plans for the project (which include 3d printing a more robust shim to attach the lens to the camera – we’re kind of sad about that, because we love the silly putty) here on her blog. The rest of the website is also well worth a browse; Katherine’s got some really interesting computer vision projects on the go. Thanks Katherine – we’re looking forward to seeing what you do next with the camera board!