爲對zedboard--pc機的ubuntu安裝Opencv(十七)的補充。
之前一直很鬱悶,opencv安裝成功後,雖然可以處理圖像,但是沒辦法顯示圖像,報錯
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, 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
configure script) in cvNamedWindow, file /home/aborn/software/OpenCV-2.4.1/modules/highgui/src/window.cpp, line 598
terminate called after throwing an instance of 'cv::Exception'
what(): /home/aborn/software/OpenCV-2.4.1/modules/highgui/src/window.cpp:598: error: (-2) The function is not implemented. Rebuild the library with Windows, 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 configure script in function cvNamedWindow
若用opencv自帶的函數進行顯示,需要在linux下安裝gtk等若干第三方庫。
第一步:
sudo
apt-get
install
build-essential
libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev libswscale-dev libjasper-dev cmake cmake-curses-gui
第二步:
tar -xvjf OpenCV-2.3.1.tar.bz2 這裏的目錄是/usr/Opencv2.3.1
第三步:
進入目錄/usr/Opencv2.3.1,mkdir build,並且進入build目錄,執行命令
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ../ 注意../一定不要丟了,因爲他需要CMakeList.txt文件,在上一層目錄下。/usr/local是安裝目錄。
第四步:
ls一下,可以看到build文件夾多了一些文件,執行
ccmake ./
這裏要千萬注意注意:
書上要把一些需要第三方支持的庫設置位OFF,之前安裝的一些就是第三方的庫,疑問:??如果要顯示圖像WITH_GTK,關掉就算你按照了gtk的庫也是沒用的。
這次只把WITH_1394,WITH_CUDA,WITH_EIGEN,WITH_FFMPEG,其它都沒變。
然後完成後,按下c鍵進行配置,在按下G來產生Makefile
第五步:
make
第六步
make
install,安裝完成後,可以在/usr/local/lib 目錄下看看這些鏈接庫,用file libopencv_calib3d.so.2.3.1 查看信息,得到如下信息:
file
libopencv_calib3d.so.2.3.1
libopencv_calib3d.so.2.3.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamicallylinked,BuildID[sha1]=0xb0d34a38b76b0bbe88511635df3bde46c281bb56,
not stripped
第七步:配置和測試
配置:
在pc機上運行opencv的話必須要配置,具體步驟如下:
vim /etc/ld.so.conf.d/opencv.conf
添加/usr/
local
/lib
,退出保存
ldconfig(必須在root權限下):
vim /etc/
bash
.bashrc
,在末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/
local
/lib/pkgconfig
export
PKG_CONFIG_PATH
保存,重啓終端
測試:
cd /usr/OpenCV-2.3.1/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect baboon.jpg