(转载)ubuntu卸载opencv并重装opencv3.0.0
ubuntu卸载opencv并重装opencv3.0.0
一、 卸载opencv2.4.9: Going to the "build" folder directory of opencv from terminal, and execute the following:
- $ sudo make uninstall
- $ cd ..
- $ sudo rm -r build
- $ 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
二、 安装opencv,去CSDN下载opencv3.0.0和ippicv_linux_20141027.tgz(http://download.csdn.net/detail/yunlong782/8940743)。
install essential packages
[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
- $ sudo apt-get install cmake cmake-qt-gui
- 解压opencv3.0.0,并进入目录,建立build目录并进去build目录打开终端,并输入:$ cmake-gui
- 在source 目录里添加:文件目录如(../../../opencv-3.0.0.0-beta),在build目录添加build目录(如:../../../opencv-3.0.0.0-beta/build),在CUDA_GENERATION 选择Kepler(我的显卡型号:gtx 980m)
- configure,此时会处错误,原因是由于ippicv_linux_20141027.tgz不正确。把下载好的ippicv_linux_20141027.tgz替换掉出错路径下的ippicv_linux_20141027.tgz即可。重新configure
- generate
- 进入build目录 $ make -j8
7.在build目录下 $ sudo make install - 写入opencv路径:sudo sh -c 'echo "usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
- sudo ldconfig
三、测试opencv是否装好
1.创建工作目录
$ mkdir ~/opencv-lena
$ cd ~/opencv-lena
$ gedit DisplayImage.cpp
- 编译如下代码
#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;
}
- 创建CMake文件
$ gedit CMakeLists.txt
写入如下内容
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
- 编译
$ cd ~/opencv-lena
$ cmake .
$ make
- 执行
此时opencv-lena文件夹中已经产生了可执行文件DisplayImage,下载lena.jpg放在opencv-lena下,运行
$ ./DisplayImage lena.jpg
- 结果