Ubuntu14.04配置opencv2.4.12

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuxiangxxl/article/details/79914041

1. 先下载OpenCV的源码  https://github.com/Itseez/opencv/tree/2.4


2. 解压到任意目录

    unzip opencv-2.4.zip

3.进入源码目录

    cd opencv-2.4

创建release目录

mkdir release

4. 事先安装一些软件

    sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config Python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev  


5.  进入cmake

    cd cmake

6. cmake编译生成Makefile,

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..  

    安装所有的lib文件都会被安装到/usr/local目录


7. 编译,并安装

    make

    sudo make install  

-------------------------------------------------------------------------------------

补充部分:

Now you have to configure OpenCV. First, open the opencv.conf file with the following code:

sudo gedit /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

/usr/local/lib


Run the following code to configure the library:

sudo ldconfig

Now you have to open another file:

sudo gedit /etc/bash.bashrc

Add these two lines at the end of the file and save it:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.


--------------------------------------------------------------------------------------




8. 测试,在某个目录下建立一个test.cpp文件

[cpp]  view plain  copy
  1. #include <cv.h>  
  2. #include <highgui.h>  
  3.   
  4. using namespace cv;  
  5.   
  6. int main(int argc, char* argv[]) {  
  7.     Mat image;  
  8.     image = imread(argv[1], 1);  
  9.   
  10.     if (argc != 2 || !image.data) {  
  11.         printf("No image data\n");  
  12.         return -1;  
  13.     }  
  14.   
  15.     namedWindow("Display Image", CV_WINDOW_AUTOSIZE);  
  16.     imshow("Display Image", image);  
  17.     waitKey(0);  
  18.     return 0;  
  19. }  

9. 同目录,新建一个文件CMakeLists.txt,写入如下内容

[plain]  view plain  copy
  1. project(test)    
  2. find_package(OpenCV REQUIRED)    
  3. add_executable(test test)    
  4. target_link_libraries(test ${OpenCV_LIBS})    
  5. cmake_minimum_required(VERSION 2.8)  

10. 编译成可执行文件

    cmake .

    make



11.  随便弄个jpg图片做个测试,注意要和上面那个可执行文件放在同一目录下面,我这里名字取的是test.jpg。


12.    ./test   test.jpg    

    如果能看到照片,那就表示成功了。

猜你喜欢

转载自blog.csdn.net/liuxiangxxl/article/details/79914041