Ubuntu 12.04 下安裝配置編譯使用OpenCV 2.3.0 全過程

來源:互聯網
上載者:User

經過幾天的努力,初步完成了對opencv2.3.0的安裝和使用。記錄下過程希望對他人有協助。

首先,的步驟當然是下載和編譯opencv,根據這位大神提供的思路,安裝和編譯還是比較輕鬆。主要有以下幾步:

1、下載opencv解壓opencv

2、進入解壓後的目錄,建立一個目錄用來安放編譯後的檔案,目錄的名字自己取,我去的名字是release

3、不記得哪個版本的opencv之後,編譯前的配置不再用configure檔案了。而改用cmake ,所有趕緊看看自己的系統中是否安裝了cmake 沒有的話,趕緊安裝吧。

4、進去我們剛才建立的目錄中,運行cmake

5、之後就是make && make install 了。

這裡特別提示你需要安裝一個庫,不然在啟動並執行時候你就會發現一個問題

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/bush/OpencvSrc/OpenCV-2.3.0/modules/highgui/src/window.cpp, line 275

terminate called after throwing an instance of 'cv::Exception'

what():  /home/bush/OpencvSrc/OpenCV-2.3.0/modules/highgui/src/window.cpp:275: 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

問題的原因資訊已經提示了要安裝libgtk2.0-dev and pkg-config,這個不難,鍵入以下的命令就可以了。pkg-config已經在系統中安裝了。

以上幾個步驟對應的命令是

1、
wget http://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.3/OpenCV-2.3.0.tar.bz2

tar -xvf OpenCV-2.3.0.tar.bz2

2、

cd OpenCV-2.3.0
sudo mkdir relese
cd relese
sudo apt-get install libgtk2.0-dev

3、這裡就需要看看你的系統中是否安裝了cmake了,如果沒有安裝,就請自行安裝吧命令也很簡單

sudo apt-get install cmake

我一般將安裝和編譯的過程寫在指令碼當中,

#########################################################################
# File Name: Install_cmake.sh
# Author: ma6174
# mail: ma6174@163.com
# Created Time: 2014年02月28日 星期五 13時32分53秒
#########################################################################
#!/bin/bash


##############################################
# FunctionName:echocolor
# Author: bush2582
# Role:the output will have color
# Created Time:
##############################################
echocolor(  )
{
  echo -e "\e[0;33m${@}\e[0m";
}

 

##############################################
# FunctionName:InstallGCC
# Author: bush2582
# Role:check g++ is already in system
# Created Time:
##############################################
function InstallGCC (  )
{
 
 which g++;
 if [ $? -eq 1 ];
 then
  read -p " g++ is not installed in this system do you want to install? (Y/y/n/N) " ynInstall_GCC;
 
  if [ $ynInstall_GCC = "Y" ] || [ $ynInstall_GCC = "y" ] ;
  then
   #echo " now we will install g++ ";
   echocolor "now we will install g++"
   sudo apt-get install g++;
  fi
 else
  echocolor "g++ already install in this system ";
 fi
}
##############################################
# FunctionName:InstallCmake
# Author: bush2582
# Role:install Cmake
# Created Time:
##############################################

function InstallCmake(  )
{
  InstallGCC;
  echocolor " now we will star the program that CMake is installed in this system ";
  cd cmake-2.8.0;
  ./configure;
  sudo make;
  sudo make install;
  exit 0;
}

 


#########################################################################
read -p "Do you want to download Cmake? (Y/y/n/N)?" downyn
if [ $downyn = "Y" ] || [ $downyn = "y" ];
then
 wget http://down1.chinaunix.net/distfiles/cmake-2.8.0.tar.gz;
 echocolor "now Staring Tar cmake";
 tar -xvf cmake-2.8.0.tar.gz;
else
 echocolor "now Staring Tar cmake";
 tar -xvf cmake-2.8.0.tar.gz;
fi

read -p " Do you want to install camke now (Y/y/n/N)? " yn
if [ $yn = "y"  ] || [ $yn = "Y"  ] ;
then 
 InstallCmake;
else
 exit 0;
fi

3、這裡的/usr/local/opencv是我自訂在系統中安裝的路徑

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

推薦閱讀:

Ubuntu 12.04 安裝 OpenCV2.4.2

CentOS下OpenCV無法讀取視頻檔案

Ubuntu 12.04下安裝OpenCV 2.4.5總結

Ubuntu 10.04中安裝OpenCv2.1九步曲

基於QT和OpenCV的Face Service系統

  • 1
  • 2
  • 3
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.