[cpp]?view plain?copy
sudo?apt-get?install?build-essential?
sudo?apt-get?install?cmake?
sudo?apt-get?install?libgtk2.0-dev?
sudo?apt-get?install?pkg-config?
sudo?apt-get?install?python-dev?python-numpy?
sudo?apt-get?install?libavcodec-dev?libavformat-dev?libswscale-dev?libjpeg-dev?libpng-dev?libtiff-dev?libjasper-dev?
進入目錄opencv-3.1.0,然後cmake生成makefile:
先把我的安裝歷史紀錄給大家看下吧,大家也好心裏有數
[html]?view plain?copy
make?.?
然後
[html]?view plain?copy
make?&&?make?install?
這下子代碼插入了。
現在我們做的就是該怎麽找到opencv庫了:
首先打開這個文件,在最後壹行添加壹句話,當然它也可能是空的,沒影響。
[html]?view plain?copy
sudo?vim?/etc/ld.so.conf.d/opencv.conf?
最後壹行添加[html]?view plain?copy
/usr/local/lib?
運行以下代碼配置庫:
[html]?view plain?copy
sudo?ldconfig?
現在打開另壹個文件,添加環境變量:sudo gedit /etc/bash.bashrc
在這個文件的末尾添加下面兩行:
[html]?view plain?copy
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig?
export?PKG_CONFIG_PATH?
然後測試:
[html]?view plain?copy
cd?~?
vim?hello.cpp?
[cpp]?view plain?copy
#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;?
}?
然後編譯:
[html]?view plain?copy
g++?`pkg-config?--cflags?opencv`?-o?hello?hello.cpp?`pkg-config?--libs?opencv`?
然後運行:
[html]?view plain?copy
./hello?psb\?1.jpg?
後面的psd是圖片路徑,由於我是在服務器上運行的,所以沒辦法顯示出來,服務器默認是沒有裝Xwindow的,我裝了,但是報了壹堆錯,就放棄了
[html]?view plain?copy
root@iZ28gdz88j1Z:~#?./hello?psb\?1.jpg?
(Display?Image:25620):?Gtk-WARNING?**:?cannot?open?display:?
希望能夠幫助到妳