OpenStreetMap

Photogrammetry update

Posted by Ainsworth on 6 February 2010 in English.

As promised in my previous post, here is a how-to of using Bundler to generate 3D models for use in OSM.

My setup:

I used a fairly generic digital compact camera, a Pentax Optio S5i.
I'm running an up-to date copy of Ubuntu 9.10 (64 bit) on my Satellite L300 laptop, a really not very powerful machine.
I have followed these instructions on a 32 bit Ubuntu LiveCD to double check they work.

I'm posting this in the hope some of you may find it interesting/useful however I'm no guru on linux and if it doesn't work for you I probably won't be of much use to you in fault finding. For Windows users, I've read that this will work under cygwin but I've never tried, and, not being a Windows user myself I probably won't be trying.

Taking photos:

I went to Market Harborough town centre and took about 65 photos of the Church from various viewing points. It's best to stand well back and get as much of the object in view as possible with maximal overlap of images, not just lots of close ups where each photo overlaps a little with the next as you might do when making a panorama.

I read somewhere along the way that a photo every 15 degrees as you walk around might work well but I'm still experimenting with this and don't have any golden rules to follow. When you look at the final output of the program you can get an idea from the numbering of the ply files which photos were used and which ones weren't, this may be the best guide to you after a while.

Don't go overboard on photos though, from my experience so far, the cpu time in seconds to crunch a set is:
t = 2.5*n^2 + 90n
For 65 photos that equals about 80 minutes. In the end I think only 30-35 of my photos were actually used in the reconstruction so if I'd been more careful about which photos I used, I could have achieved the same results in under 10 minutes. This software isn't as optimised as Microsoft's Photosynth so don't dump 500 photos on it and expect it to finish processing in under a day. 5 well placed photos could well be better than 50 photos of rubbish.

Also think about scaling down the photos, mine were 2560x1920 but I later found that scaling down to 2048x1536 almost halved the cpu time while still getting good results. A handy command to resize images is:
for f in *.JPG; do convert "$f" -resize 2048x1536 -quality 100 "$f"; done

Bundler:

Go to http://phototour.cs.washington.edu/bundler/ and download v0.3 binary distribution. Extract this anywhere you like. All commands I run assume it is located on your desktop in a folder called bundler.

As the readme supplied with Bundler explains, the process is made up of a number of steps. The first examines each image and extracts focal length information where it can, it then identifies key-points in each image. Next, keypoints are matched between images to find any correspondences before finally performing the bundle adjustment and calculating the 3d positions of the keypoints.

To extract keypoints you will need David Lowe's SIFT binary from http://www.cs.ubc.ca/~lowe/keypoints/. Download the demo and from it, extract the file called sift into bundler/bin.

Now open a terminal and install imagemagick
sudo apt-get install imagemagick
This is needed to convert the images from jpg to pgm so sift can read them.

We will also need another library, libgfortran.so.3.
sudo apt-get install libgfortran3
I don't know what this is used for but the code won't work without it.

Before we run Bundler, we need to specify where the libANN_char.so library is by typing:
export LD_LIBRARY_PATH="/home/user/Desktop/bundler/bin/"
I've read a couple of discussions on forums about how this shouldn't be neccesary and various solutions were talked about but that didn't work for me so I just accept that I have to do this each time I want to run Bundler. If anyone knows how to fix this please let me know.

Finally, go to the directory containing the images you want to run. Bundler comes with a few test images you can play with. Run:
cd /home/ubuntu/Desktop/bundler/examples/kermit
../../RunBundler.sh

I refer readers to http://binarymillenium.com/2009/07/building-bundler-v03-on-ubuntu.html to see what a sucessful run looks like. A folder called bundle will be created containing the output ply files, these are built sequentially as each photo is examined. Therefore the highest numbered file will contain all the data points, there's no need to combine files. Binary Milleniums blog also contains instruction on how to get bundler working under Ubuntu. He mentions installing various packages however, using a LiveCD just now I found almost all of these to be unnecessary. If my guide doesn't work for you, follow his instructions.

Many programs can open ply files but the easiest I found to use was Blender. This can be found easily enough through the Ubuntu Software Centre so I won't go in to detail on that. Once you've opened the program, click File>Import>Stanford PLY and select your file.

Assuming things ran as they should, you should see a point cloud that resembles the objects in the photos. Curiously, the photos provided with Bundler of kermit didn't process well and produced a ply file that looked nothing like the objects in question, however further testing with photos of my own confirmed bundler was working fine. That's just my experience anyway.

When you're ready to take a screenshot of blender, open the view menu and ensure the view is set to orthographic, not perspective. Now open JOSM, install the PicLayer plugin and import your screenshot. Assuming you got a good quality bundle you should be able to do some good tracing.

Note, while this software recovers 3D data from photos, it is only the relative positions of points that is recovered. Scale and absolute position are still unknown and you will need a gpx file and perhaps some reference dimensions to trace correctly.

This zip file contains some of the photos I took of the church along with the final ply file. (link to follow, it's still uploading).

Legality:

Bundler is licensed under GPL and assuming you took the photos yourself or have permission I can't see any reason this can't be used in OSM. However the SIFT binary is only a demo and doesn't appear to be free. Whether this has any impact on your ownership of the final ply files or terms of use for projects like OSM I have no idea. Even so, it's probably better than creating a photosynth on Microsofts website and then intercepting the data as it's transmitted. Personally, I would like to bypass the legal stuff by doing the keypoint matching by hand and modifying Bundler to use my keypoints rather than data generated using SIFT. The matching is not 100% and some sets of photos have failed to match properly despite being of reasonable quality.

Location: Little Bowden, Harborough, Leicestershire, England, LE16 8AQ, United Kingdom

Discussion

Comment from JohnSmith on 7 February 2010 at 04:35

As per a comment on your previous entry, this would be better on the wiki that way others can help contribute etc.

Comment from slashme on 7 February 2010 at 06:25

I've dumped this text at http://wiki.openstreetmap.org/wiki/Photogrammetry - please see the talk page: maybe one should go straight to PGM instead of a 100% jpeg? I dunno.

Log in to leave a comment