Ubuntu 12.04 下安装配置编译使用OpenCV 2.3.0 全过程


经过几天的努力,初步完成了对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的人脸识别系统

  • 1
  • 2
  • 3
  • 下一页

相关内容

    暂无相关文章