歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 12.04 下安裝配置編譯使用OpenCV 2.3.0 全過程

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

日期:2017/2/28 14:35:36   编辑:Linux教程

經過幾天的努力,初步完成了對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: [email protected]
# 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 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV無法讀取視頻文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基於QT和OpenCV的人臉識別系統 http://www.linuxidc.com/Linux/2011-11/47806.htm

Copyright © Linux教程網 All Rights Reserved