Configure opencv3.1.0 development environment under Ubuntu
1, recently work in the use of Ubuntu under the QT and OPENCV Library development application software (computer vision processing), special OPENCV configuration process records, for sharing
2. Step description
First, install the OpenCV3.1.0
1. Use wget to download OpenCV source code
URL: https://github.com/Itseez/opencv/archive/3.1.0.zip
sudo apt-get install wget sudo wget https://github.com/Itseez/opencv/archive/3.1.0.zip
2. Unzip the zip source file
sudo apt-get install unzipsudo unzip opencv-3.1.0.zip
3. Enter the source directory and create the release directory
cd opencv-3.1.0mkdir release
4. Installing dependent libraries
sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev
5. Enter the release directory, when installing OPENCV, All Files will be placed in this release directory
cd release
6. CMake Compile OpenCV source code, install all LIB files will be installed in the/usr/local/opencv3.1.0 directory
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3.1.0 ..
Note that there is an error in CMake to 92%, and for this error, we put
/own defined path/opencv-3.1.0/modules/ CUDALEGACY/SRC under graphcuts.cpp # if! defined (Have_cuda) | | defined (Cuda_disabler)
Modified to:#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)即可,然后再次cmake即可。
7. Installation
sudo make install -j8
Second, configuration pkg-config (optional)
1. Create a pkgconfig directory
mkdir /usr/local/pkgconfig
2. Copy the opencv.pc file to the Pkgconfig directory
cp /usr/local/opencv3.1.0/lib/pkgconfig/opencv.pc /usr/local/pkgconfig/opencv3.1.pc
3. Open bash with vim with administrator privileges
sudo vim ~/.bashrc
4. Add environment variables to the last line of the file
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/pkgconfigexport PKG_CONFIG_PATH
5.wq after saving the file, the source file (Execute script)
source ~/.bashrc
6. Test Pkgconfig
< Span class= "hljs-comment" >pkg-config --libs Opencv3. 1.0
三、配置lib环境变量
1、用vim打开/etc/ld.so.conf文件,添加上以下两行:
①/usr/loacal/li
②/root/opencv/opencv-3.1.0/release/lib
四、程序测试
在任意一个目录下创建test.cpp文件,用vi编写如下内容:
- #include <stdio.h>
- #include <opencv2/opencv.hpp>
- using namespace CV;
- int main (int argc, char** argv)
- {
- if (argc!= 2)
- {
- printf ("Usage:DisplayImage.out <image_path>\n");
- return-1;
- }
- Mat image;
- Image= Imread (argv[1], 1);
- if (!image.data)
- {
- printf ("Noimage data\n");
- return-1;
- }
- Namedwindow ("DisplayImage", cv_window_autosize);
- Imshow ("DisplayImage", image);
- Waitkey (0);
- return 0;
- }
使用g++编译的时候使用命令:
g++ ' pkg-config--cflags opencv '-O test test.cpp ' pkg-config--libs OpenCV '
五、其他
参考博客:
http://blog.csdn.net/c406495762/article/details/62896035
(4) Detailed steps for configuring the Opencv3.1.0 development environment under Linux (Ubuntu)