Opencv2.4.9 + ffmpeg1.2.12 installation configuration and problem solution under Ubuntu 14.04

In the process of video processing, two feature extraction methods, space-time interest points (stip) and improved dense trajectories (IDT), are used. We can find the open algorithm source code on the author’s home page. They need opencv and ffmpeg to run smoothly under Linux. We have used these two tools before, but now we want to use them again after changing the working environment, but there are still many problems in the process of configuration and installation. Therefore, I feel it is necessary to record the specific process, problems and solutions for future use, and hope to bring a little help to others.


Opencv2.4.9 and ffmpeg 1.2.12 source package download

These two software in the official website can be directly found in various versions of the source code package, download, compile and install. If you don’t particularly need the latest version of the software, I suggest that you use the earlier version that has been used by most people, and you can easily find the corresponding solution when there is a problem. I chose opencv2.4.9 and ffmpeg 1.2.12.

Opencv2.4.9 download
the official website provides download links from the earlier version 1.0.0 to 3.1 and 2.4.13, which means that different operating systems have different software packages
http://opencv.org/downloads.html
The download address of version 2.4.9 that I used is as follows:
0 https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/downloadFFmpeg1.2.12 The latest version of ffmpeg is 3.1.4, and the update speed is relatively fast. Personal choice of the early version 1.2.12 has been able to meet the actual needs, and the download address is as follows:
0 https://ffmpeg.org/olddownload.html

Ffmpeg compilation configuration

Ffmpeg is a leading multimedia framework, which can be used to record, convert digital audio and video, and convert them into open source programs. It includes the leading audio/video coding libraries libavcodec, libavutil, libavformat, etc.

1. Uninstall the previously installed ffmpeg and x264 software
in order to prevent version problems, it is recommended to uninstall the previously (possibly) installed version first. The order is as follows:

sudo apt-get -qq remove ffmpeg x264 libx264-dev

2. Install dependencies and related software

sudo apt-get install yasm
sudo aptitude install libx264-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev  libxext-dev libxfixes-dev

3. Compile and install
decompress the ffmpeg package and enter the decompressed directory

cd ffmpeg-1.2.12

Environment configuration [4]

./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-pthreads --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab --enable-libvorbis --enable-nonfree --enable-pic --enable-shared

Note that there may be carriage return or character problems in the process of copying. If there is a problem with the prompt command, you need to carefully check the space and carriage return. If you use prefix to specify the installation path of the software, you need to modify the corresponding path in the configuration file so that the system can find the installation path of ffmpeg

vi /etc/profile

Press insert and add the following two lines at the end of the file:

export FFMPEG_HOME=/usr/local/ffmpeg 
export PATH=$FFMPEG_HOME/bin:$PATH

Press ESC and enter “: WQ” to exit and save, and then make the above changes take effect. The command is as follows:

source profile

After all configuration is completed, prepare to install. The command is as follows:

make
make install

After installation, you will see three directories in/usr/local/ffmpeg: Bin executable file directory, lib static and dynamic link library directory, and header files used in include programming.

4. Check whether the installation configuration is correct
it is said on the Internet that you can test whether the installation is successful by executing ffplay to play the video file in the bin directory. However, I did not generate ffplay after compiling and installing. There are only ffmpeg and ffserver in the bin directory. Therefore, we directly check whether the version is correct, and there is no problem when we use it later. The order is as follows:

ffmpeg -version

The correct version and configuration information appears, indicating that the installation is successful.

Opencv compilation and installation

The full name of OpenCV is: open source computer vision library. Opencv is a cross platform computer vision library based on BSD license (open source), which can run on Linux, windows and Mac OS operating systems. It is lightweight and efficient, which is composed of a series of C functions and a small number of C + + classes. It also provides the interfaces of python, ruby, MATLAB and other languages, and realizes many general algorithms in image processing and computer vision [5].

1. Install dependencies

sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libopencore-amrnb-dev libopencore-amrwb-dev x264 v4l-utils 

2. Compile and install
to unzip the downloaded opencv package and enter the unzipped directory

cd opencv-2.4.9

Create compile directory, compile and install

mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install

It takes a long time to compile here. After completion, the following prompt information will be printed on the last line:

-- Configuring done
-- Generating done
-- Build files have been written to: /opt/opencv-2.4.9

During the compilation process, you may stay in the line “configuring done” for a long time. Don’t stop the compilation in a hurry. You need to wait patiently for the compilation to complete. During the installation process, there will be a progress prompt in the form of “[10%]” percentage, and the process will be very slow. Please wait patiently.

Tip: after cmake is completed, relevant information will appear, in which you can check whether ffmpeg has been supported. If yes is supported, ffmpeg will appear after it. There are also some encoding and formats with yes.

3. Environment configuration
all library files are installed under/usr/local/lib by default, and all header files are installed under/usr/local/include/opcv * /. Modify the environment configuration [6], and the command is as follows:

vim /etc/ld.so.conf

Press the insert key to add in the last line of the file

/usr/local/lib

Press ESC key to enter “: WQ” to exit and save, and then execute the following command:

ldconfig

At this point, opencv installation is complete.

Libcxcore. So. 2 cannot find a solution to the problem

After opencv is installed, the IDT algorithm can run normally, but the following errors appear when executing stip program:

./bin/stipdet: error while loading shared libraries: libcxcore.so.2: cannot open shared object file: No such file or directory

Look at the problem, it means that the shared library file libcxcore. So. 2 can’t be found during the execution of the program. This file or path doesn’t exist. From the online search results, most of the problems are prepared to use stip to obtain video features, but dense track programs do not have this problem. This problem and several solutions are available on the stackoverflow website for reference [7].

I didn’t succeed in creating soft links. Maybe I didn’t set it correctly at that time, and then I didn’t have root permission. Finally, I adopted a temporary method. To set the search directory of shared library, the command is as follows:

export LD_LIBRARY_PATH=[enter your path]/opencv-2.4.9/release/lib

When executing some external programs under Linux, you may be prompted that the shared library cannot be found, which is quite common. The reason for this problem is that although the shared library has been installed, the program cannot find the file when it is ready to call.

My problem is that the shared library file is installed in other “non/lib or/usr/lib” directory, but after the installation, the non root user does not have the permission to add a path in the “/ etc/LD. So. Conf”. So export is a global variable LD_ LIBRARY_ Path, and then run the program will go to this directory to find the shared library [8].

Execute stip program

If you directly execute “.”/bin/stippet – help “in this directory, you will not be able to execute. You must turn stippet and stipshow into executable files. For convenience, I directly changed it to fully open executable permissions [9]. The order is as follows:

chmod 777 bin/stipdet
chmod 777 bin/stipshow

For programs with dense trajectories, the same method can be used to execute normally. In addition, the global variable of export will no longer take effect every time the command window is closed. Therefore, before executing the stip program, we must first set the search directory of the shared library according to the above method, and there will be no problem that libcxcore. So. 2 cannot be found.

Opencv version view

During use, you may need to check the installed version of OpenCV. You can use the following command [10]:

pkg-config --modversion opencv

PKG config is a very useful tool for compiling applications and library files. One of its functions is to check the version number of the library.

Python calls opencv module

If you need to use Python to call opencv module, you can install Python first and then load CV [4]. The order is as follows:

sudo apt-get install python-opencv
sudo apt-get install python-numpy
python
import cv


References: <
> 1] https://www.di.ens.fr/~laptev/interestpoints.html
[2] https://lear.inrialpes.fr/people/wang/improved_trajectories
[3] https://ffmpeg.org/about.html
[4] http://blog.csdn.net/u010106759/article/details/51931815
[5] http://opencv.org/
[6] http://blog.csdn.net/firefoxbug/article/details/7554409
[7] http://stackoverflow.com/questions/5212728/libcxcore-so-2-missing-in-opencv
[8] http://blog.csdn.net/sahusoft/article/details/7388617
[9] http://blog.chinaunix.net/uid-21880738-id-1813031.html
[10] http://blog.csdn.net/ppp2006/article/details/47445903

Read More: