If you're interested in BBB and OpenCV, you must have known Michael Darling's guide. Seriously, if you have not read it, go read it please to understand the hard works that people have done to make our life with BBB much much easier. These two blog posts about BBB and OpenCV are also very interesting [1] & [2].
That guide is dated to September 24, 2013. Since then, many things have changed, and fortunately, things are much easier now. I will point out steps that need to be changed from the guide (due to links changes, sources changes, ...). I will also include some steps that I hope will make things easier new comers.
My steps assume that your main operating system is Windows.
This is is intended to be used side by side with Michael Darling's guide. Michael Darling wrote a really excellent guide, I just want to update and add some steps.
You have to install Ubuntu onto your BBB. Go to here, I recommend getting Ubuntu Precise 12.04. I also recommend flash it directly to your eMMC, as your eMMC is much faster than any uSD card. You can do that by:
We need to install dependencies, tons of them. Make an "install.sh" file with the following content is the easiest and most automatic way to do so:
1 2 3 4 5 6 7 | sudo apt-get -y install build-essential checkinstall cmake cmake-curses-gui pkg-config yasm sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev sudo apt-get -y install python-dev python-numpy sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev sudo apt-get -y install x264 v4l-utils ffmpeg sudo apt-get -y install libgtk2.0-dev |
And one tip for you, doing "sudo apt-get clean" after installing packages will clean the download cache and free up disk space (it can free 200-400MB, which matters much on BBB).
Recently, libjpeg-turbo have been choose to be default libjpeg-dev package for armhf distro, so you don't have to built it from source like in the guide.
I highly recommend doing this step. Building OpenCV on a single core ARM board takes 3-4 hours and will make your little ARM CPU hot as hell. Setting up distcc and configure OpenCV correctly, we can build it in 15 minutes, and BBB CPU is not even warm.
About the compiler, you can use the one in the guide, version 4.8-2013.08 or use the updated here.
The new commands for installing distcc are:
1 2 3 4 | wget https://distcc.googlecode.com/files/distcc-3.1.tar.bz2
tar xjf distcc-3.1.tar.bz2
cd distcc-3.1
./configure --with-gtk --disable-Werrormakesudo make install
|
Get a USB flash drive, and use MiniTool Partition Wizard Home Edition (free) to format it to Ext2. Remember to give it a name when doing so, the name must contain no space, for example "myusb". Plug it in your BBB.
The new commands for building OpenCV:
1 2 3 4 5 6 7 8 | su cd /media/myusb wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.8/opencv-2.4.8.zip unzip opencv-2.4.8.zip cd opencd-2.4.8 mkdir build cd build cmake -D CMAKE_C_FLAGS='-O3 -mfpu=neon -mfloat-abi=hard' -D CMAKE_CXX_FLAGS='-O3 -mfpu=neon -mfloat-abi=hard' -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DENABLE_VFPV3=ON -DENABLE_NEON=ON .. |
We need to disable some part of the build to speed it up:
1 | ccmake . |
Remember the dot "." after ccmake command. Check to make sure that ENABLE_NEON and ENABLE_VFPV3 are ON. Now we disable BUILD_PERF_TESTS, BUILD_TESTS, and ENABLE_PRECOMPILED_HEADERS. Some explanations:
- ENABLE_NEON and ENABLE_VFPV3: to enable hardware acceleration
- BUILD_PERF_TESTS and BUILD_TESTS: set these 2 to OFF to disable the building of these 2 test suites of OpenCV. Why do we want to not build the tests? Building these tests takes lots lots of time, and I'm sure that you don't have enough patient to run those tests. There is an individual executable for each module of OpenCV, and I tried running the test for opencv_core myself just to see me interrupted the test after waiting for ~20 minutes.
- ENABLE_PRECOMPILED_HEADERS: by theory, using precompiled headers speed up compilation. But that's not in this case. Our BBB CPU will have to compile those headers alone, as distcc can't do this. And doing this takes BBB CPU lots of time. The precompiled headers in this case will only speed up compilation on host machine, which is already powerful. Less work for BBB = faster overall compilation :).
Follow the on-screen instructions, press "c" to reconfigure and then "g" to regenerate. Finally, we can begin compilation:
1 | make -j6 |
The "-jX" after make command allow parallelization, set X to the number of jobs your host allow.
My distcc host is a virtual machine running Ubuntu 12.04. My desktop is powered by an AMD Phenom II X4 and 4GB RAM so I give my virtual Ubuntu 3 cores and 1.5GB RAM. Therefore the number of jobs is 6. My setup built OpenCV in just 15 minutes.
Some final notes:
Some final notes:
- Environmental variables in Unix systems are only temporary, they got wiped out after reboot or even on session exit. So if you plan to keep using distcc, you will have to edit the ".profile" file in your home folder. Just paste the export commands at the end of that file. The variables will be created every time you log in using that username.
- Don't forget to tell your system where to look for OpenCV runtime libraries. Edit /etc/ld.so.conf and add "/usr/local/lib" and the end of it. Then run "sudo ldconfig".
- The easiest way to edit those files from Windows is using WinSCP (free). Using WinSCP, you just need to navigate to the needed file, double click it, a text editor will open it up, and when you save, WinSCP will put the updated version in the right place. Nice and clean. Log in as your username to edit the ".profile" file, and as root to edit /etc/ld.so.conf.
This "guide" lacks lots of stuffs. That's my intention, so you have to read this guide in combination with Michael Darling's one.
Feel free to leave suggestions and/or questions :).
Update: Watch the Final test run of my Thesis on YouTube
Update: Watch the Final test run of my Thesis on YouTube