Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Building OpenCV 3.1.0 from Source for Visual SLAM Applications

Tech Apr 17 12

To compile OpenCV 3.1.0 successfully on modern Ubuntu systems for use with Visual SLAM projects, follow these corrected steps to resolve common dependency and build-time issues.

Step 1: Install Required System Dependencies

Begin by installing essential libraries. Due to package version changes in newer Ubuntu releases, adjust the original command as follows:

sudo apt-get install build-essential libgtk2.0-dev libvtk6-dev libjpeg-dev libtiff5-dev libopenexr-dev libtbb-dev

If libjasper-dev is missing, manually add the Xenial security reopsitory:

echo "deb http://security.ubuntu.com/ubuntu xenial-security main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install libjasper-dev

After this, re-run the full dependency installation command to ensure all packages are present.

Step 2: Download and Extract OpenCV 3.1.0

Download the OpenCV 3.1.0 source archive from the official GitHub releases page. Extract it to your preferred working directory—for example, ~/src/opencv-3.1.0.

Step 3: Configure and Build with CMake

Navigate into the extracted folder and create a build directory:

cd opencv-3.1.0
mkdir build && cd build

Configure the build with custom installation prefix and disable problematic features:

cmake -D CMAKE_BUILD_TYPE=Release \
      -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 \
      -D ENABLE_PRECOMPILED_HEADERS=OFF \
      -D BUILD_opencv_python2=OFF \
      -D BUILD_opencv_python3=OFF ..

If the build fails due to slow or failed download of ippicv, manually download the file:

wget https://raw.githubusercontent.com/Itseez/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz

Place it under:

opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/

Then resume compilation:

make -j$(nproc)
sudo make install

Step 4: Resolve Compilation Errors

If you encounter an error in cap_ffmpeg_impl.hpp related to undefined macros, edit the file at:

modules/videoio/src/cap_ffmpeg_impl.hpp

Add these lines near the top (after includes):

#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020

This resolves compatibility issues with newer FFmpeg versions.

Step 5: Avoid Python Binding Conflicts

The error constant l_MAGIC_VAL already exists typically occurs late in compilation due to symbol conflicts in Python bindings. Disabling Python module builds during CMake configuration prevents this entirely.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.