(4) Detailed steps for configuring the Opencv3.1.0 development environment under Linux (Ubuntu)

Source: Internet
Author: User

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编写如下内容:
  1. #include <stdio.h>
  2. #include <opencv2/opencv.hpp>
  3. using namespace CV;
  4. int main (int argc, char** argv)
  5. {
  6. if (argc!= 2)
  7. {
  8. printf ("Usage:DisplayImage.out <image_path>\n");
  9. return-1;
  10. }
  11. Mat image;
  12. Image= Imread (argv[1], 1);
  13. if (!image.data)
  14. {
  15. printf ("Noimage data\n");
  16. return-1;
  17. }
  18. Namedwindow ("DisplayImage", cv_window_autosize);
  19. Imshow ("DisplayImage", image);
  20. Waitkey (0);
  21. return 0;
  22. }

  23. 使用g++编译的时候使用命令:

    g++ ' pkg-config--cflags opencv '-O test test.cpp ' pkg-config--libs OpenCV '

  24. 五、其他

    参考博客:http://blog.csdn.net/c406495762/article/details/62896035


(4) Detailed steps for configuring the Opencv3.1.0 development environment under Linux (Ubuntu)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.