Updated: Check out my paper on parallelizing SfM across a compute cluster
VisualSFM by Changchang Wu is a great tool for creating 3D reconstructions of photos. It’s really easy to use, but really hard to install. This guide will take you through getting it working on a clean installation of Ubuntu 12.04 Desktop 64-bit. I’ll warn you: you’ll need to install packages, download academic software, and edit and compile source code. This will also require more than 2 GB of hard drive space. If you run into any trouble, be sure to leave me a reply at the bottom of the post.
Getting Started
Start by creating a working directory for this procedure. I’m working in “~/vsfm”, which I’ll also refer to as “/home/scott/vsfm” when instructions require an absolute path. So, open a terminal and get started:
$ mkdir vsfm $ cd vsfm
(Note, whenever you see a line beginning with “$”, that means you should type that line in your terminal.)
Setup NVIDIA CUDA (Optional)
VisualSFM supports acceleration on CUDA-enabled NVIDIA GPUs. It is also possible to set up VisualSFM to use ATI/AMD GPUs via OpenCL or to simply not use GPU acceleration. However, since I have an CUDA-enabled NVIDIA GPU, these instructions assume you do, too. (Coincidentally, the process should be easier without CUDA support, but you’ll have to figure out the details on your own.)
Grab the Linux 64-bit driver and the CUDA toolkit from the CUDA Downloads page. NVIDIA provides decent installation instructions here, but I’ll offer some quick tips for Ubuntu users:
- Be sure to update your Ubuntu system before installation the CUDA software because if Ubuntu pushes you new Linux kernel, you’ll need to re-install the CUDA driver from scratch.
- Install the driver first (i.e. devdriver_4.2_linux_64_295.41.run) per NVIDIA’s instructions; to shutdown Ubuntu’s graphical desktop press Ctrl+Alt+F1 to get a terminal, login, then run “sudo /etc/init.d/lightdm stop”
- You can safely ignore the warning about the setup script failing.
- Reboot from the command line after driver installation completes (“sudo reboot”).
- Then install the CUDA toolkit after a reboot.
Download the Necessary Software
Let’s get started by getting the major pieces of software that comprise VisualSFM: SiftGPU, Multicore Bundle Adjustment, PMVS-2, CMVS, Graclus 1.2, and, of course, VisualSFM. You’ll also need to refer to certain installation instructions. You can find these applications and documentation pages at the following locations:
- VisualSFM: Installation Instructions and Download VisualSFM_linux_64bit.zip (4.9 MB)
- SiftGPU: Installation Instructions and Download SiftGPU-V382.zip (5.3 MB)
- Multicore Bundle Adjustment: Home Page and Download pba_v1.0.4.zip (1021 KB)
- PMVS-2: Installation Instructions and Download pmvs-2.tar.gz (315 MB) Note: link updated 5/9/13
- CMVS: Installation Instructions and Download cmvs-fix2.tar.gz (232 MB) Note: link updated 5/9/13
- Graclus 1.2: Home Page contains a form that asks for an email address prior to download
8/20/12: New link to PMVS-2 download, which points to an older version. This older archive contains compiled object files which are necessary to get PMVS/CMVS working. Alternatively, you can download the newest release and then grab mylapack.o here, which you’ll need for later steps in this tutorial.
5/9/13: Also note, CMVS and PMVS-2 are now hosted at http://www.di.ens.fr/. All links have been updated.
Install Dependency Packages
Next, you need to install a number of dependencies available through Ubuntu’s package manager. I’m sure you can these elsewhere on the web, but I highly recommend installing through Aptitude. To get all the required packages, just run this line (which might take a few minutes to download and install… also, be sure to copy and paste the full line below, which scrolls horizontally!):
$ sudo apt-get install libgtk2.0-dev libglew1.6-dev libglew1.6 libdevil-dev libboost-all-dev libatlas-cpp-0.6-dev libatlas-dev imagemagick libatlas3gf-base libcminpack-dev libgfortran3 libmetis-edf-dev libparmetis-dev freeglut3-dev libgsl0-dev
8/20/12: Added freeglut3-dev, libgsl0-dev
Build VisualSFM
Start by building VisualSFM, which should go smoothly.
$ unzip VisualSFM_linux_64bit.zip $ cd vsfm $ make
Now the VisualSFM GUI is built, but it can’t actually generate 3D reconstructions yet.
8/20/12: If you run into errors with the GTK libraries, see Shyam Nambiar’s comments below on using pkg-config.
Build SiftGPU
Next, build SiftGPU with CUDA support. Like VisualSFM, this should also “just work” if CUDA is setup properly. When you’re done, copy the shared library into the “vsfm/bin” folder.
$ unzip SiftGPU-V382.zip $ cd SiftGPU $ make $ cp bin/libsiftgpu.so ../vsfm/bin
Build Multicore Bundle Adjustment (a.k.a. “pba”)
Now things start getting tricky. Unzip (“unzip pba_v1.0.4.zip”), and then you’ll need to edit two source code files. In “pba/src/pba”, edit “SparseBundleCU.h” and “pba.h” by adding this one line to the top of each file:
#include <stdlib.h>
Now you can compile if you simply type “make” in the “~/vsfm/pba” directory.
Hack PMVS-2
You don’t actually have to install Bundler in order to use PMVS-2 with VisualSFM (the installation instructions are a little unclear). There’s a 64-bit Linux binary distrubtion of PMVS-2 available, but it won’t run on Ubuntu 12.04 64-bit without some hacking. If you try running the binary, you’ll get an error similar to this:
./pmvs2: error while loading shared libraries: libjpeg.so.62: cannot open shared object file: No such file or directory
This is because the package was compiled in an older version of Red Hat, and the binary can’t find two of the required shared libraries (even though they are, in fact, installed). Unfortunately, you also can’t just run “make” to compile your own binary because you’ll get an error with the “mylapack” library. Here’s a work-around that lets you use the compiled mylapack object file but re-compiles the rest of PMVS-2 to produce a working binary.
$ tar xf pmvs-2.tar.gz $ cd pmvs-2/program/main/ $ cp mylapack.o mylapack.o.backup $ make clean $ cp mylapack.o.backup mylapack.o $ make depend $ make
Build Graclus 1.2
The Graclus instructions actually work. After you untar graclus1.2.tar.gz, as promised, you do need to edit “Makefile.in” to set “-DNUMBITS=64″ so that the library works with your 64-bit VisualSFM installation. After making that change to the makefile, just type “make”, and it should work.
Hack CMVS
OK, now the hard part. First, unzip CMVS and grab that mylapack.o file from the PMVS-2 binary distribution:
$ cd ~/vsfm $ tar xf cmvs-fix2.tar.gz $ cp pmvs-2/program/main/mylapack.o cmvs/program/main/
Next, edit the source file “cmvs/program/base/cmvs/bundle.cc” by adding these includes at the top of the file:
#include <vector> #include <numeric>
And now edit “cmvs/program/main/genOption.cc” by adding this include statement at the top:
#include <stdlib.h>
OK, almost there! Now edit the CMVS Makefile (in cmvs/program/main) so that lines 10-17 read as follows (but be sure to replace “/home/scott/vsfm/” with the path to your installation):
#Your INCLUDE path (e.g., -I/usr/include) YOUR_INCLUDE_PATH = #Your metis directory (contains header files under graclus1.2/metisLib/) YOUR_INCLUDE_METIS_PATH = -I/home/scott/vsfm/graclus1.2/metisLib #Your LDLIBRARY path (e.g., -L/usr/lib) YOUR_LDLIB_PATH = -L/home/scott/vsfm/graclus1.2
OK, now go ahead and build the thing, and then copy the three binaries into the VisualSFM binary directory.
$ cd ~/vsfm/cmvs/program/main $ make $ cp cmvs ~/vsfm/vsfm/bin $ cp pmvs2 ~/vsfm/vsfm/bin $ cp genOption ~/vsfm/vsfm/bin
8/20/12: corrected filenames above
Running VisualSFM
Finally, add VisualSFM to your path and LD_LIBRARY_PATH. You can do this by adding lines to your ~/.bashrc file. Here’s what I added to the bottom of mine:
export PATH=$PATH:/home/scott/vsfm/vsfm/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/scott/vsfm/vsfm/bin
And you can now run VisualSFM by opening a terminal and typing “VisualSFM&”. Easy, right?

Hi Scott,
Thanks for the helpful post! However I am getting stuck with the following error(s) at make for vsfm
GlobalTasks.cpp:(.text+0xf51): undefined reference to `gtk_box_pack_end’
build/GlobalTasks.o: In function `GlobalTasks::TerminateTaskViewer()’:
GlobalTasks.cpp:(.text+0x10f3): undefined reference to `gtk_widget_destroy’
collect2: ld returned 1 exit status
make: *** [VisualSFM] Error 1
I think its got to do something with gtk but I dont know exactly what it is.
Any help greatly appreciated!
Regards,
Shyam
Shyam, did you install GTK 2 dev package?
sudo apt-get install libgtk2.0-dev
Hello Scott,
This is a very helpful tutorial. Thanks a lot.
I was able to compile everything seemingly fine but when I start pairwise matching on vsfm, I get an error ERROR: unable to load libsiftgpu.so even though siftgpu compiled fine and the SimpleSIFT binary in SiftGPU/bin runs successfully. Am I missing something?
Thanks a lot.
Scott,
I tried the command line interface of VisualSFM and that seems to be working fine. For some reason, the gui version of VisualSFM can’t load libsiftgpu.so. Any help with that?
Thanks a lot.
Kossi,
You just need to make sure libsiftgpu.so is on your LD_LIBRARY_PATH. I assume you’re launching the GUI from a terminal (i.e. typing “VisualSFM &”)? If that’s the case, edit set your LD_LIBRARY_PATH in your ~/.bashrc. After changing your .bashrc you need to close/open the terminal or “source ~/.bashrc”. If you can’t get that to work, you could also symlink the library to /usr/lib, which is a little hacky, but it would work.
$ sudo ln -s /path/to/libsiftgpu.so /usr/lib/libsiftgpu.so
Hope that helps.
-Scott
Hi Scott,
I do have both GTK2 and GTK3 installed so your install command returns
“libgtk2.0-dev is already the newest version.”
After looking at VSfM’s makefile, I thought it’s because the gtk path is not added to the pkg-config path because when I ran
$ pkg-config –modversion gtk+-2.0
I got-
“pkg-config –modversion gtk+-2.0
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc’
to the PKG_CONFIG_PATH environment variable
No package ‘gtk+-2.0′ found”
So, I edited the PKG_CONFIG_PATH according to
$ export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig/
and then when I tried the make, it worked!
I also had to do
$ sudo apt-get install freeglut3-dev
(just in case any beginner like me gets stuck)
I have now gotten stuck at the PMVS hack because I am unable to find the ‘mylapack.o’ file in pmvs-2/program/main/
I tried the make but I get:
“g++ -O2 -Wall -Wno-deprecated -c -o pmvs2.o pmvs2.cc
In file included from ../base/pmvs/findMatch.h:19:0,
from pmvs2.cc:3:
../base/pmvs/optim.h:6:30: fatal error: gsl/gsl_multimin.h: No such file or directory
compilation terminated.
make: *** [pmvs2.o] Error 1
Any suggestions?
Regards,
Shyam
OK, I see a mistake in my post… I’ll post a correction soon. “mylapack.o” is NOT contained in pmvs-2-fix0.tar.gz. However, an older version of that file, which DOES contain mylapack.o, is still available on the website:
http://grail.cs.washington.edu/software/pmvs/pmvs-2.tar.gz
Scott,
It worked great. Thanks for your help. I hope you will keep this page active for the long term. It is a great resource.
Thanks again.
Scott,
I was finally able to get VisualSfM to work!
I had the same issue as Kossi when it came to doing the matching. Why is it that when the program is launched from the terminal, it works (after editing ~/.bashrc) and not when I double-click the file through gnome?
Here are a few edits that you can make to your post to make it comprehensive:
1) Installation of dependency packages-
For those missing freeglut and gsl
$ sudo apt-get install freeglut3-dev libgsl0-dev
2) Slight naming mistake in the last part of ‘Hack CMVS’ section while copying binaries; it should have been
$ cd ~/vsfm/cmvs/program/main
$ make
$ cp cmvs ~/vsfm/vsfm/bin
$ cp pmvs2 ~/vsfm/vsfm/bin
$ cp genOption ~/vsfm/vsfm/bin
Thanks again for the tutorial!
-Shyam
Hi Scott,
First off, thanks for posting this guide. This is easy to follow and will be a great resource for Ubuntu users. I finished the installation but am experiencing a problem similar to what Kossi described. When I try to do the pairwise matching form the GUI I get “ERROR: unable to load libsiftgpu.so” displayed in the GUI and “/home/nedhorning/vsfm/bin/sift: not found” in the terminal window. I added the following lines in my .bashrc:
export PATH=$PATH:/home/nedhorning/vsfm/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/nedhorning/vsfm/bin
and I also have the symbolic link set using:
ln -s /home/nedhorning/vsfm/bin/libsiftgpu.so /usr/lib/libsiftgpu.so
I used “cp bin/libsiftgpu.so ../bin” to copy libsiftgpu.so to /home/nedhorning/vsfm/bin
Any idea what I’m doing wrong?
All the best,
Ned
Hi Ned,
Just asking but did you try running vsfm from the terminal?
$ VisualSFM&
I also had problems similar to Kossi’s but the export statements in .bashrc followed by source worked for me ie. I didn’t have to use the symlink.
-Shyam
Hi Shyam,
Thank for the reply. I have been using the terminal to launch VisualSFM. I expect I’m doing something stupid but can’t figure it out.
Ned
Ned, no obvious solution comes to mind. Could you print some information that might be helpful for debugging?
$ which VisualSFM
$ echo $PATH
$ echo $LD_LIBRARY_PATH
$ locate libsiftgpu.so
Scott – Here is the output:
nedhorning@ubuntu-desktop:~$ which VisualSFM
/home/nedhorning/vsfm/bin/VisualSFM
nedhorning@ubuntu-desktop:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/nedhorning/vsfm/bin
nedhorning@ubuntu-desktop:~$ echo $LD_LIBRARY_PATH
:/home/nedhorning/vsfm/bin
nedhorning@ubuntu-desktop:~$ locate libsiftgpu.so
/home/nedhorning/vsfm/SiftGPU/bin/libsiftgpu.so
/home/nedhorning/vsfm/bin/libsiftgpu.so
/usr/lib/libsiftgpu.so
The path to libcudart.so is not in LD_LIBRARY_PATH, or other depending libraries of libsiftgpu.so
Thank for the tip Changchang. I copied libcudart.so.4 to ~/vsfm/bin [cp /usr/local/cuda/lib64/libcudart.so.4 libcudart.so.4] and that fixed the “unable to load libsiftgpu.so” error. I also had to copy libpba.so from ~/vsfm/pba/bin to ~/vsfm/bin for the dense reconstruction to work.
To fix the “/home/nedhorning/vsfm/bin/sift: not found” error I reinstalled the CUDA driver and Toolkit.
Thanks to everyone for your help. It’s nice to be running this under Ubuntu.
Ned
That was helpful!!! Thanks!!
Hi Scott,
Thank you very much for the helpful post! However I am getting stuck with the following error(s) at make for vsfm.
/usr/bin/ld: error: cannot find -lmultilevel
/usr/bin/ld: error: cannot find -lmultilevel
graclus.o:graclus.cc:function CMVS::Cgraclus::runSub(graphdef&, int, int, int, std::vector<long long, std::allocator >&): error: undefined reference to ‘MLKKM_PartGraphKway(int*, long long*, long long*, long long*, long long*, int*, int*, int*, int*, int*, int*, long long*, int)’
graclus.o:graclus.cc:function CMVS::Cgraclus::runSub(graphdef&, int, int, int, std::vector<long long, std::allocator >&): error: undefined reference to ‘__ComputePartitionBalance(graphdef*, int, long long*, float*)’
graclus.o:graclus.cc:function CMVS::Cgraclus::runSub(graphdef&, int, int, int, std::vector<long long, std::allocator >&): error: undefined reference to ‘ComputeRAsso(graphdef*, long long*, int)’
graclus.o:graclus.cc:function CMVS::Cgraclus::runSub(graphdef&, int, int, int, std::vector<long long, std::allocator >&): error: undefined reference to ‘ComputeNCut(graphdef*, long long*, int)’
collect2: ld returned 1 exit status
make: *** [cmvs] Error 1
Am I missing something?
Any help greatly appreciated!
Best regards,
Belle
Hi Belle,
I didn’t encounter that problem, but someone mentions something similar on Nghia Ho’s site:
http://nghiaho.com/?page_id=253
Based on the comments on that site, there might be a problem with Ubuntu’s 32-bit libraries. Which version of Ubuntu are you using? 64- or 32-bit?
-Scott
This post of great help.. for a linux Noob like me….
to compile SiftGPU v400 you may need to add next lines to /src/ProgramCU.cu:
#ifndef min
#define min(a,b) (((a) (b)) ? (a) : (b))
#endif
To solve
undefined reference to ‘MLKKM_PartGraphKway(int*, long long*, long long*, long long*, long long*, int*, int*, int*, int*, int*, int*, long long*, int)’
I had to set
COPTIONS = -DNUMBITS=64
in the graclus Makefile.in
Hi,
I has having problems with the error message “I get an error ERROR: unable to load libsiftgpu.so” which is kind of deceiving because after running “ldd libsiftgpu.so” I was able to notice that “libcudart.so.5.0 => not found” was the real issue.
To fix this issue you will need to run “ldconfig /usr/local/cuda-5.0/lib64″ … in my case 64 because I am running under 64 bits… Hope this saves you hours of frustration and confusion.
Probably a permanent fix would be to add it to your LD_LIBRARY_PATH inside .bashrc
Thanks for the wonderful tutorial.
Regarding __ComputePartitionBalance(graphdef*, int, long long*, float*)
I hit that problem. It turns out I somehow set -DNUMBITS=32 rather than 64 in graclus. I could swear I had set it to 64, so of course it was a pain to track down.
But if they don’t match between graclus and cmvs, the signatures won’t match, and you’ll get these errors.
Hi Scott,
Thanks for such a helpful post.
I was able to build VisualSFM without CUDA support successfully. I followed all the steps mentioned above except I used sift binary instead of siftGPU. But When I run VisualSFM by opening a terminal and typing “VisualSFM&”, the GUI window appears with the following errors in the terminal:
ERROR: glXChooseVisual returns NULL
Xlib: extension “RANDR” missing on display “:14.0″.
setenv LIBGL_ALWAYS_INDIRECT=yes
ERROR: glXChooseVisual returns NULL
(VisualSFM:7837): Gdk-CRITICAL **: gdk_window_move_resize_internal: assertion `GDK_IS_WINDOW (window)’ failed
(VisualSFM:7837): Gdk-CRITICAL **: gdk_window_move_resize_internal: assertion `GDK_IS_WINDOW (window)’ failed
(VisualSFM:7837): Gdk-CRITICAL **: gdk_window_show_internal: assertion `GDK_IS_WINDOW (window)’ failed
(VisualSFM:7837): Gdk-CRITICAL **: gdk_window_move_resize_internal: assertion `GDK_IS_WINDOW (window)’ failed
Also, when I add the images in the VisualSFM and click open, VisualSFM GUI disappears.
Did I miss anything during installation?
Any help will be appreciated.
Regards
Mukesh
Creating an apt-get package for VSFM, or a script to do everything you just listed would save people a lot of time.
I’ve come across a problem is the installation of the Multicore Bundle Adjustment. First, the link takes me to version 1.0.5 not 1.0.4. Is this going to be a problem? Next, should the line added be #include or #include “stdlib.h” or will it work either way? Next, where (as in what directory) should this be unzipped or compiled. “~/vsfm/pba”? Am I to unzip and compile this package inside the vsfm directory I created earlier? This would all be more clear if you had included the command lines exactly as they are to be executed. I hope to hear back form you soon. Thanks.
Phillip,
I installed using pba 1.0.4. The link must now point to a newer version. Hopefully it will work, but I haven’t tested it. I placed pba_v1.0.4.zip in my ~/vsfm folder. It then unzipped to ~/vsfm/pba/.
I had to add the line “#include <stdlib.h>” to files I mentioned to get it to compile. It’s possible that’s been fixed in the newer version — you might want to try compiling before making changes first.
-Scott