Ubuntu下安装opencv

一、下载代码

1、一些会用到的库

sudo apt-get install build-essential cmake libgtk2.0-dev libtiff4-dev  libjasper-dev libavformat-dev libswscale-dev libavcodec-dev  libjpeg62-dev pkg-config ffmpeg

注:如果在opencv安装后运行程序时莫名出现一些错误,就要看看这一步你是不是做了。


2opencv

opencv官网http://opencv.org/downloads.html下载最新版本,目前是OpenCV-2.4.2.tar.bz2


二、编译安装opencv

tar xf OpenCV-2.4.2.tar.bz2 -C ~/soft/

mv ~/soft/OpenCV-2.4.2 ~/soft/opencv

cd ~/soft/opencv

mkdir release

cd release

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

sudo make install

export LD_LIBRARY_PATH=~/soft/opencv/release/lib:$LD_LIBRARY_PATH

sudo ldconfig

pkg-config opencv –libs

三、测试一下

cd../sample/cpp/

g++ drawing.cpp -o drawing `pkg-config opencv --libs --cflags`

./drawing


四、可能会遇到的问题

1OpenCVError: Unspecified error (The function is not implemented. Rebuildthe library with Windows, GTK+ 2.x or Carbon support. If you are onUbuntu or Debian, install libgtk2.0-dev and pkg-config, then re-runcmake or configure script) in cvShowImage, file/home/lynn/soft/opencv/modules/highgui/src/window.cpp, line293
terminate called after throwing an instance of'cv::Exception'
  what(): /home/lynn/soft/opencv/modules/highgui/src/window.cpp:293:error: (-2) The function is not implemented. Rebuild the library withWindows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian,install libgtk2.0-dev and pkg-config, then re-run cmake or configurescript in function cvSho
wImage


如果运行drawing出现了上述错误,检查一下是不是安装了第一步中所说的那些库。装完后,再重复第二步就ok了。


你可能感兴趣的:(exception,Debian,function,ubuntu,library,gtk)