Notes on Installing OpenCV in a Vagrant Box

I installed OpenCV in a Vagrant box for a new project. It was a pain in the arse. The basic box I used was Official Ubuntu 13.10 daily Cloud Image amd64. After many trials and errors, these are things to note when installing OpenCV in a Vagrant box:

Build without GPU and OpenCL

When building, don’t build with GPU options:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_QT=ON -D BUILD_opencv_gpu=OFF -D BUILD_opencv_ocl=OFF ..

Building it with GPU on my local machine works, but in a VirtualBox env, there isn’t a GPU, and somehow it causes the compiler to come out with a odd error: c++: internal compiler error: Killed (program cc1plus).

Download More RAM!

I was joking about downloading more RAM. But I spent about 4 hours figuring out why my compilation would segfault. It turns out that the virtual machine has very little memory and the compiler would run out of memory for no good reason.

So this was added to my Vagrantfile:

config.vm.provider "virtualbox" do |v|
    v.memory = 1024
end

The Right VirtualBox

In VirtualBox 4.2.x, I also encountered a problem where I couldn’t list the directories of /vagrant. I discovered this problem when I was using glob to search for files in the shared directory. It would consume so much memory and then the process would be killed. Doing ls -a would also take a long time while in the box.

Turns out, it’s a known bug. My solution was simple: upgrade virtualbox to 4.3. Works beautifully now

Problems solved. It just takes 20 mins to compile OpenCV instead of 2 hours.

UPDATE:

Not Everyone has Quad Cores

I found a bug within my provisioning script. When installing OpenCV, on some of my team’s computers, the make would fail. The reason? I had make -j4 in the provisioning script. Updating it to make fixed the problem for everyone

7 Comments Notes on Installing OpenCV in a Vagrant Box

  1. Tyler

    I have always used the flag WITH_OPENCL=OFF to turn off building with OpenCL. Your build statement will still include OpenCL.

    Reply
  2. Ben

    Hey, thanks for your post. I also ran into a similar problem where I had to do “make” instead of “make -j4.” Have you had any problems with displaying images? I’m getting “(Image:3925): Gtk-WARNING **: cannot open display.” I’ve tried enabling x11 forwarding in my vagrantfile, installing xQuartz on my local machine, using vagrant ssh — -Y, and all to no avail.

    Do you have any recommendations?

    Thanks in advance for any help you can offer.

    Reply
    1. The Doctor

      I think if you use virtualbox, you gotta have a line in your vagrantfile that looks something like v.gui=true, then you can continue with your session on virtualbox’s gui thing. Else, you’d just be running your VM headless

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *