UBUNTU 下安装opencv
form step 1 to step 7 you can reference to http://docs.opencv.org/2.4.13/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
the installation guide is in the opencv online documentation which is very clear, choose which version of opencv you need, and find the installation guide from introduction documentation.
1.从opencv官网下载源代码。
2.解压到任意文件夹
tar zxvf opencv..
3. 进入源码目录,创建release目录
cd opencv[Tab] 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.
cd release
6.cmake编译OpenCV源码,安装所有的lib文件都会被安装到/usr/local目录下 /*也可以安装在 /usr/local/opencv/目录下*/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
/*注意,后面有两个" .. "*/
7.
sudo make install
8. 配置library
sudo gedit /etc/ld.so.conf.d/opencv.conf
添加:
/usr/local/lib /*或者/usr/local/lib/opencv,总之要与安装路径对应起来*/
9. update config
sudo ldconfig
10. add these two lines to "~/.bashrc":
export PKG_CONFIG_PATH="/usr/local/opencv/lib/pkgconfig:$PKG_CONFIG_PATH"
PKG_CONFIG_PATH is the path to opencv.pc, export the path to your system
so that ervery time you boot your computer it will know where the opcncv.pc is.
11. make the path valid:
sudo source ~/.bashrc
12. 测试,在某个目录下建立一个DisplayImage.cpp文件
1 #include <cv.h> 2 #include <highgui.h> 3 4 using namespace cv; 5 6 int main(int argc, char* argv[]) 7 { 8 Mat image; 9 image = imread(argv[1], 1); 10 11 if (argc != 2 || !image.data) 12 { 13 printf("No image data\n"); 14 return -1; 15 } 16 17 namedWindow("Display Image", CV_WINDOW_AUTOSIZE); 18 imshow("Display Image", image); 19 waitKey(0); 20 return 0; 21 }
13. 编译:
g++ DisplayImage.cpp -o DisplayImage `pkg-config opencv --cflags --libs`
14. 运行:
./DisplayImage lena.jpg