opencv multi-version installation

Use the command to see the current opencv version:

pkg-config --modversion opencv

It comes with opencv-2.4.9

Install opencv3.1

Install the dependencies of opencv

sudo apt-get install build-essential libgtk2.0-dev libvtk5-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev libtbb-dev

Enter the decompressed opencv installation package, create a new directory, the directory name is build, and enter the directory

mkdir build && cd build

input the command

sudo mkdir -r /usr/local/opencv310
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_CUBLAS=0 -D WITH_CUDA=0 -D WITH_CUFFT=0 -D CMAKE_INSTALL_PREFIX=/usr/local/opencv310 ..
make
sudo make install

Here, the installation directory of opencv3.3 is placed in the /usr/local/opencv310 folder, and the parts related to CUDA are also annotated (the currently installed CUDA7.5 cannot be compiled when compiling)

Next, you need to configure the file, and set PKG_ CONFIG_PATH by modifying the bashrc file (later found that you need to change LD_LIBRARY_PATH) <quote>

sudo gedit ~/.bashrc

add at the end of the file

export PKG_CONFIG_PATH=/usr/local/opencv310/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/opencv310/lib

After saving, use the command

source ~/.bashrc

At this time, using the command, the opencv version has become 3.1

pkg-config --modversion openc v

When you are using the cmake tool, you can use opencv3.1 by adding the path to CMakeLists.txt

set(OpenCV_DIR /usr/local/opencv310/share/OpenCV)
find_package(OpenCV 3.1 REQUIRED

include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS} /usr/local/opencv310/include)
find_package("/usr/local/opencv310/include/opencv2")

When you want to go back to using opencv2, replace find_package(OpenCV 3.1 REQUIRED ) with find_package(OpenCV REQUIRED ), and delete the upper and lower lines of the code.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325166617&siteId=291194637