district10 / cmake-templates

Some CMake Templates (examples). Qt, Boost, OpenCV, C++11, etc 一些栗子
http://blog.tangzhixiong.com/post-0100-cmake-templates.html
MIT License
531 stars 138 forks source link

HOWTO: OpenCV 2 & OpenCV 3 #4

Open district10 opened 8 years ago

district10 commented 8 years ago

Windows

When you find_package( OpenCV REQUIRED ) in CMakeLists.txt, it just look for OpenCVConfig.cmake under OpenCV_DIR, aka include( $ENV{OpenCV_DIR}/OpenCVConfig.cmake ).

If you want to use OpenCV2 & OpenCV3 in your system at the same time. Here is my solution:

1.

First goto OpenCV official download page, download opencv-2.4.x.exe and opencv-3.1.x.exe.

2.

Second, extract them, set these two proper environment variables:

add to PATH:

reboot may needed.

3.

Last, generated VS2010, VS2015 project to use OpenCV 2, OpenCV 3 with CMake, respectively.

You can see opencv2 / opencv3 examples in:

district10 commented 7 years ago

VC Version Number & Prebuild

compiler IDE
vc14 Visual Studio 2015 (OpenCV3)
vc12 Visual Studio 2013 (OpenCV2, OpenCV3)
vc11 Visual Studio 2012 (OpenCV2)
vc10 Visual Studio 2010
vc9 Visual Studio 2008
vc8 Visual Studio 2005
vc7.1 Visual Studio .NET 2003
vc7 Visual Studio .NET 2002
vc6 Visual Studio 6.0
district10 commented 7 years ago

Ubuntu

prerequisites:

sudo apt-get install --assume-yes build-essential cmake git
sudo apt-get install --assume-yes build-essential pkg-config unzip ffmpeg qtbase5-dev python-dev python3-dev python-numpy python3-numpy
sudo apt-get install --assume-yes libopencv-dev libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
sudo apt-get install --assume-yes libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install --assume-yes libv4l-dev libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
sudo apt-get install --assume-yes libvorbis-dev libxvidcore-dev v4l-utils

CV3

cmake, make.

CV2

cmake, make.

Usage

When you want opencv 2,:

export OpenCV2_DIR=/home/tzx/Downloads/archive/opencv-2.4.13/build
cd ~/git/cmake-templates/opencv
mkdir build && cd build
cmake ..
make

When you want opencv 3:

cd ~/git/cmake-templates/opencv3
mkdir build && cd build
export OpenCV2_DIR=/home/tzx/Downloads/archive/opencv-3.1/build
cmake ..
make

I installed OpenCV 3 and added these lines to my .zshrc:

export OpenCV2_DIR=/home/tzx/Downloads/archive/opencv-2.4.13/build2
export OpenCV3_DIR=/usr/local/share/OpenCV

Refs

district10 commented 7 years ago

In my case, better not configure CUDA to the WONT_INSTALL opencv 2. Or you may come across link error.

JingeTu commented 7 years ago

I just set OpenCV_DIR in CMakeLists.txt where my OpenCVConfig.cmake locates.

district10 commented 7 years ago

@JingeTu Like this: include( $ENV{OpenCV_DIR}/OpenCVConfig.cmake )?