1、 卸載opencv2.4.9: Going to the "build" folder directory of opencv from terminal, and execute the following:
1. $ sudo make uninstall
2. $ cd ..
3. $sudo rm -r build
4. $ sudo rm -r /usr/local/include/opencv2 /usr/local/include/opencv /usr/include/opencv /usr/include/opencv2 /usr/local/share/opencv /usr/local/share/OpenCV /usr/share/opencv /usr/share/OpenCV /usr/local/bin/opencv* /usr/local/lib/libopencv*
這一步可能有error
下面執行以下操做:
5. sudo apt-get –purge remove opencv-doc opencv-data python-opencv
2、 安裝opencv,去CSDN下載opencv3.0.0和ippicv_linux_20141027.tgz(http://download.csdn.net/detail/yunlong782/8940743)。
install essential packages
sudo rm -r build
[compiler] sudo apt-get install build-essential [required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
使用cmake-gui安裝,首先安裝cmake和cmake-qt-gui
1. $ sudo apt-get install cmake cmake-qt-gui
2. 解壓opencv3.0.0,並進入目錄,創建build目錄並進去build目錄打開終端,並輸入:$ cmake-gui
3. 在source 目錄裏添加:文件目錄如(../../../opencv-3.0.0.0-beta),在build目錄添加build目錄(如:../../../opencv-3.0.0.0-beta/build),在CUDA_GENERATION 選擇Kepler(個人顯卡型號:gtx 980m)
4. configure,此時會處錯誤,緣由是因爲ippicv_linux_20141027.tgz不正確。把下載好的ippicv_linux_20141027.tgz替換掉出錯路徑下的ippicv_linux_20141027.tgz便可。從新configure
5. generate
6. 進入build目錄 $ make -j8
7.在build目錄下 $ sudo make install
8. 寫入opencv路徑:sudo sh -c 'echo "usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
9. sudo ldconfig
3、測試opencv是否裝好
1.建立工做目錄
$ mkdir ~/opencv-lena
$ cd ~/opencv-lena
$ gedit DisplayImage.cpp
2. 編譯以下代碼
#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("No image data \n"); return -1; } namedWindow("Display Image", WINDOW_AUTOSIZE ); imshow("Display Image", image); waitKey(0); return 0; }
3. 建立CMake文件
$ gedit CMakeLists.txt
寫入以下內容python
cmake_minimum_required(VERSION 2.8) project( DisplayImage ) find_package( OpenCV REQUIRED ) add_executable( DisplayImage DisplayImage.cpp ) target_link_libraries( DisplayImage ${OpenCV_LIBS} )
4. 編譯
$ cd ~/opencv-lena
$ cmake .
$ make
5. 執行
此時opencv-lena文件夾中已經產生了可執行文件DisplayImage,下載lena.jpg放在opencv-lena下,運行linux
$ ./DisplayImage lena.jpg
6. 結果