Resolving Common Issues During OpenCV 3.1.0 Installation
Dependency Setup
Initial attempt to install required packages may fail:
sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev
A correction involves updating package versions and adddressing a missing component:
sudo apt-get install build-essential libgtk2.0-dev libvtk6-dev libjpeg-dev libtiff5-dev libjasper-dev libopenexr-dev libtbb-dev
If the libjasper-dev package remains unfound, resolve by enabling the Ubuntu security repository:
- Edit the sources list:
sudo vim /etc/apt/sources.list - Append the following line at the end:
deb http://security.ubuntu.com/ubuntu xenial-security main
3. Save the file and update the package cache:
```bash
sudo apt-get update
- Verify the package availability:
apt-cache search libjasper-dev - Install the package:
sudo apt-get install libjasper-dev
Now, re-run the corrected dependency installation command.
Source Acquisition
Obtain the OpenCV 3.1.0 source archive from the official GitHub Releases page and extract it too a working directory.
Build Configuration
Navigate to the extracted source directory and create a build folder:
mkdir build
cd build
Configure the build with CMake. Specify a custom installation directory to avoid conflicts:
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/opencv-3.1.0 \
-DENABLE_PRECOMPILED_HEADERS=OFF \
-DBUILD_opencv_python2=OFF \
-DBUILD_opencv_python3=OFF ..
Note on ippicv: If the configuration stalls due to a slow donwload of the ippicv library, manually download ippicv_linux_20151201.tgz from the official OpenCV third-party repository. Place the downloaded file in the corresponding local directory within the source tree (e.g., opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/).
Compilation
Compile the library using multiple cores:
make -j4
If compilation fails, check for specific errors.
Macro Definition Fix
An error regarding missing FFmpeg macros might occur. Add the following definitions to opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp:
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020
Duplicate Symboll Fix
A late-stage error about a duplciate constant (l_MAGIC_VAL) can be resolved by ensuring Python bindings are disabled, which is already handled in the CMake command above.
After successful compilation, install the library:
sudo make install