在Ubuntu 12.04.02上设置/安装OpenCV 2.4.6.1+ [英] Setting/Installing up OpenCV 2.4.6.1+ on Ubuntu 12.04.02

查看:202
本文介绍了在Ubuntu 12.04.02上设置/安装OpenCV 2.4.6.1+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在Ubuntu 12.04.1上使用了OpenCV 2.4.5与某些配置和软件包,但在Ubuntu 12.04.2上升级到OpenCV 2.4.6.1有问题。



我想分享一些想法(从SO,ubuntu.org,asklinux.org等许多来源收集的值得注意的信息的汇编,当然也可以尝试几个程序)



以下是最终得到我的信息。



注意:确保卸载先前安装的OpenCV,FFMpeg和其他依赖关系。



步骤1(安装ffmpeg和依赖项)






 #goto http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/ 
#下载最新的稳定的opencv,如2.4.6.1(http://sourceforge.net/projects/ opencvlibrary / files / opencv-unix / 2.4.5 / opencv-2.4.5.1.tar.gz / download)到当前目录(如home或〜/ Document)
#cd / opt
#tar -xvf< path-to-d ownload-folder> /OpenCV-2.4.6.1.tar.gz
#cd OpenCV-2.4.6.1
#在当前目录下创建一个边框(在上一步之后,这应该是< opencv-dir> ),称为准备
#cd prepare
#将以下脚本复制到gedit并将其另存为当前目录,这应该是< opencv-dir> / prepare
#检查对应在脚本中使用的URL用于最新版本的软件包,并根据需要进行替换
#打开终端并导航到
以上使用的位置#sudo chmod + x install.sh
#./install






  echo任何预装的ffmpeg,x264和其他依赖项(并非所有以前安装的依赖项)
sudo apt-get remove ffmpeg x264 libx264-dev libvpx-dev librtmp0 librtmp-dev libopencv-dev
sudo apt - $更新

arch = $(uname -m)
如果[$ arch==i686-o$ arch==i386-o$ arch ==i486-o$ arch==i586];然后
flag = 0
else
flag = 1
fi

echo安装依赖关系
sudo apt-get install autoconf automake make g ++ curl cmake bzip2 python unzip \
build-essential checkinstall git git-core libass-dev libgpac-dev \
libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \
libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev

echo下载yasm(x264和FFmpeg使用的汇编程序)
#use git或tarball(不是两者)
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar。 gz
cd yasm-1.2.0

echo安装yasm
./configure
make
sudo make install
cd ..

echo'READ NOTE BELOW从http://wiki.serviio.org/doku.php?id=build_ffmpeg_linux中提取
echo'新版本的x264默认支持OpenCL的。如果没有安装或没有意义(例如,在VMWare上的Ubuntu 12.04LTS)添加以配置其他选项--disable-opencl。没有这个选项ffmpeg无法配置(错误:libx264未找到)'

echo下载x264(H.264视频编码器)
#使用git或tarball(不是两者)
#git clone http://repo.or.cz/r/x264.git或
git clone git://git.videolan.org/x264.git
cd x264
#wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20130801-2245-stable.tar.bz2
#tar -xvjf x264-snapshot-20130801-2245 -stable.tar.bz2
#cd x264-snapshot-20130801-2245-stable /

echo安装x264
如果[$ flag -eq 0];然后
./configure --enable-static --disable-opencl
else
./configure --enable-shared --enable-pic --disable-opencl
fi
make
sudo make install
cd ..

echo下载fdk-aac(AAC音频编码器)
#使用git或tarball两个)
git clone --depth 1 git://github.com/mstorsjo/fdk-aac.git
cd fdk-aac

echoinstalled fdk-aac
autoreconf -fiv
./configure --disable-shared
make
sudo make install
cd ..

echo安装libmp3lame -dev(MP3音频编码器)
sudo apt-get install libmp3lame-dev

echo下载libopus(Opus音频解码器和编码器)
wget http: /downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
tar xzvf opus-1.0.3.tar.gz
cd opus-1.0.3

echoinstalled libopus
./configure --disable-shared
make
sudo make install
cd ..

echo下载libvpx VP8 / VP9视频编码器和解码器)
#使用git或tarball (不是两个)
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
#wget http://webm.googlecode.com /files/libvpx-v1.1.0.tar.bz2(这似乎不是更新,但如果以下的fedoraproject链接不可用,仍然可以使用))
#wget http://pkgs.fedoraproject.org /repo/pkgs/libvpx/libvpx-v1.2.0.tar.bz2/400d7c940c5f9d394893d42ae5f463e6/libvpx-v1.2.0.tar.bz2
#tar xvjf libvpx-v1.2.0.tar.bz2
#cd libvpx-v1.2.0

echo安装libvpx
./configure --disable-examples
make
sudo make install
cd ..

sudo ldconfig

回声下载ffmpeg
#git clone http://repo.or.cz/r/ffmpeg.git
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg /
#wget http://ffmpeg.org/releases/ffmpeg-2.0.tar.bz2
#tar - xvjf ffmpeg-2.0.tar.bz2
#cd ffmpeg-2.0 /

echoinstalled ffmpeg
if [$ flag -eq 0];然后
./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable -libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx
else
./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable -libvpx --enable-shared
fi

make
sudo make install
哈希-r

cd ..#向上移动一个级别准备文件夹
cd ..#向上移动一级到opencv文件夹

echo检查看是否使用新的ffmpeg
ffmpeg 2& 1 | head -n1

sudo ldconfig



步骤2(安装OpenCV和必需的包)



  echo安装Dependenices
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev

echo安装视频I / O库,支持Firewire摄像机和视频流媒体库
sudo apt-get install libav-tools libavcodec-dev libavformat-dev libswscale-dev libdc1394-22- dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev v4l-utils v4l-conf

echo安装Python开发环境和Python数值库
sudo apt-get install python-dev python-numpy

echo安装并行代码处理库(Intel tbb库)
sudo apt-get install libtbb-dev

echo安装Qt开发库
sudo apt-get install libqt4-dev libgtk2.0-dev

echo安装其他依赖项(如果需要的话)向上级别当前版本的包)
sudo apt-get install patch subversion ruby​​ librtmp0 librtmp-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev libxvidcore-dev

echo安装可选包
sudo apt-get install libdc1394-utils libdc1394-22-dev libdc1394-22 libjpeg-dev libpng-dev libtiff-dev libjasper-dev



步骤3(运行ldconfig)



  #打开一个新的终端窗口
#打开/etc/ld.so.conf并检查
#如果包含引用的路径/ usr / lib和/ usr / local / lib存在在文件中。如果没有,请手动添加或
sudo echo/ usr / local / lib>> /etc/ld.so.conf
sudo echo/ usr / lib>> /etc/ld.so.conf
#执行以下
sudo ldconfig



步骤4a(构建和安装操作系统使用)



 #仍然确保您尚未关闭新的终端窗口步骤3 
#执行以下
mkdir os_build
cd os_build
cmake -DCMAKE_BUILD_TYPE = RELEASE -DCMAKE_INSTALL_PREFIX = / usr / local -DBUILD_NEW_PYTHON_SUPPORT = ON -DINSTALL_PYTHON_EXAMPLES = ON -DWITH_TBB = ON -DWITH_V4L = ON -DINSTALL_C_EXAMPLES = ON -DBUILD_EXAMPLES = ON -DWITH_QT = ON -DWITH_OPENGL = ON -DWITH_OPENCL = ON -DWITH_EIGEN = ON -DWITH_OPENEXR = ON ..

make
sudo make install

#将以下内容添加到用户环境变量〜/ .bashrc
export LD_LIBRARY_PATH = $ {LD_LIBRARY_PATH}:/ usr / local / lib
export PKG_CONFIG_PATH = $ {PKG_CONFIG_PATH}: / usr / local / lib / pkgconfig
#执行以下
sudo ldconfig
#开始使用并享受opencv,应该已经安装到任何这些loca
#/ usr / local / include / opencv2,/ usr / local / include / opencv,/ usr / include / opencv,/ usr / include / opencv2,/ usr / local / share / opencv
#/ usr / local / share / OpenCV / usr / share / opencv / usr / share / OpenCV,/ usr / local / bin / opencv *,/ usr / local / lib / libopencv *



步骤4b(构建Java使用):可选



 #仍然确保您没有关闭在STEP 4中打开的新终端窗口
#执行以下
cd ..
mkdir java_build
cd java_build
cmake -DCMAKE_BUILD_TYPE = RELEASE -DBUILD_SHARED_LIBS = OFF -DINSTALL_PYTHON_EXAMPLES = ON -DWITH_TBB = ON -DWITH_V4L = ON -DINSTALL_C_EXAMPLES = ON -DBUILD_EXAMPLES = ON -DWITH_QT = ON -DWITH_OPENGL = ON -DWITH_OPENCL = ON -DWITH_EIGEN = ON -DWITH_OPENEXR = ON ..

make

#您可以检查java_build / bin目录以找到jar和libopencv_java.so文件供您开发
#As在文档中指出,Java绑定动态库是全部的优点,即不依赖于其他OpenCV库,但包含
中的所有OpenCV代码



STEP 5 (安装v4l:注意:安装v4l-utils后,opencv安装适用于Ubuntu 12.04.2& OpenCV 2.4.6.1)



 #仍然确保您没有关闭在STEP 3中打开的新终端窗口
# goto http://www.linuxtv.org/downloads/v4l-utils
#下载最新的v4l,如v4l-utils-0.9.5.tar.bz2
#将下载的文件复制到当前终端目录(之前的步骤,应该是< opencv-dir> / prepare)
#执行以下
tar -xvjf v4l-utils-0.9.5.tar.bz2
cd v4l-utils-0.9.5 /
./configure
make
sudo make install
cd ..
cd ..#(转到< opencv- dir>)
sudo ldconfig



值得注意



 #查看opencv&其他lib文件被存储,执行:


pkg-config --cflags opencv

(输出将来)
-I / usr / include / opencv



pkg-config --libs opencv

(输出将作为)
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ --ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

#如下图所示,上述路径需要编译您的opencv程序。

#写一个简单的C程序来测试,通过将程序保存在名为DisplayImage.c的文件中

#include< stdio.h>
#include< opencv2 / highgui / highgui.hpp>

int main(int argc,char * argv []){
IplImage * img = 0; / *指向图像的指针* /
printf(Hello\\\
);

if(argv [1]!= 0)
img = cvLoadImage(argv [1],0); // 1 for color
else
printf(Enter filename\\\
);

if(img!= 0){
cvNamedWindow(Display,CV_WINDOW_AUTOSIZE); //创建一个窗口
cvShowImage(Display,img); //在窗口中显示图像
cvWaitKey(0); //等到用户点击一个键
cvDestroyWindow(Display);
}
else
printf(File not found\\\
);

return 0;
}

#编写一个简单的C ++程序来测试,通过将程序保存在名为DisplayImage.cpp的文件中

#include< stdio.h>
#include< opencv2 / opencv.hpp>
#include< opencv2 / highgui / highgui.hpp>

使用命名空间cv;

int main(int argc,char ** argv)
{
Mat image;
image = imread(argv [1],1);

if(argc!= 2 ||!image.data)
{
printf(No image data \\\
);
return -1;
}

namedWindow(显示图像,CV_WINDOW_AUTOSIZE);
imshow(显示图像,图像);

waitKey(0);

return 0;
}

#编译&运行:



g ++< filename:例如DisplayImage.c或DisplayImage.cpp> `pkg-config --cflags --libs opencv`&& ./a.out img





g ++ -I / usr / include / opencv -I / usr / local / include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree< filename:eg DisplayImage.c或DisplayImage.cpp> &安培;&安培; ./a.out img

其中img是具有扩展名在同一文件夹内的任何图像的名称。
您应该可以在不同的窗口中看到Hello和图像。

如果这样运行,Congrats!现在您可以使用opencv lib运行任何C / C ++程序。


#现在,通过为其创建快捷方式来简化上述大型命令:
转到您的本地主目录(cd / home /),并使用gedit(文件将被隐藏)。在文件中附加以下内容:



alias gcv =g ++ -I / usr / include / opencv -I / usr / local / include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree

并保存。关闭终端并再次打开(因为这个过程需要终端终端)

#现在,去包含一个示例程序& do



gcv< filename:例如DisplayImage.c或DisplayImage.cpp> &安培;&安培; ./a.out





gcv< filename:例如DisplayImage.c或DisplayImage.cpp>
./a.out input_img.jpg

您可以看到命令现在变得相似到$ cc filename.c,$。/ a.out,它们通常用于编译和执行C / C ++程序。






有些方法检查是否安装了所有的lib文件 -

  apt-cache search opencv 

返回:

  libcv-dev -  libcv-dev的翻译包
libcv2.3 - 计算机视觉库 - libcv *翻译包
libcvaux-dev - libcvaux-dev的翻译包
libcvaux2.3 - 计算机视觉库 - libcvaux翻译包
libhighgui-dev - libhighgui-dev的翻译包
libhighgui2.3 - 计算机视觉库 - libhighgui翻译包
libopencv-calib3d-dev - libopencv-calib3d的开发文件
libopencv-calib3d2.3 - 计算机视觉相机校准库
libopencv-contrib-dev - libop的开发文件encv-contrib
libopencv-contrib2.3 - 计算机视觉contrib库
libopencv-core-dev - libopencv-core的开发文件
libopencv-core2.3 - 计算机视觉核心库
libopencv-dev - opencv的开发文件
libopencv-features2d-dev - libopencv-features2d的开发文件
libopencv-features2d2.3 - 计算机视觉功能检测和描述符提取库
libopencv-flann -dev - libopencv-flann的开发文件
libopencv-flann2.3 - 计算机视觉多维空间库中的聚类和搜索
libopencv-gpu-dev - libopencv-gpu
的开发文件libopencv-gpu2.3 - 计算机视觉GPU处理库
libopencv-highgui-dev - libopencv-highgui的开发文件
libopencv-highgui2.3 - 计算机视觉高级GUI和媒体I / O库
libopencv-imgproc-dev - 开发文件为libopencv-imgproc
libopencv-imgproc2.3 - 计算机视觉图像处理库
libo pencv-legacy-dev - libopencv-legacy的开发文件
libopencv-legacy2.3 - 计算机视觉遗产库
libopencv-ml-dev - libopencv-ml的开发文件
libopencv-ml2。 3 - 计算机视觉机器学习库
libopencv-objdetect-dev - 开发文件为libopencv-objdetect
libopencv-objdetect2.3 - 计算机视觉对象检测库
libopencv-video-dev - 开发文件对于libopencv视频
libopencv-video2.3 - 计算机视觉视频分析库
opencv-doc - OpenCV文档和示例
python-opencv - 计算机视觉库的Python绑定


解决方案

感谢您的信息。我试图运行这些命令,但遇到了几个问题。我正在使用全新的Ubuntu 12.04安装。



1)第一个apt-get remove命令问我是否要删除很多我不是的东西舒适的去除,像LibreOffice。我没有删除这个步骤中的任何东西,我认为这样可以,因为我安装的唯一程序是Java SDK和JRE。为什么你选择这么大的程序列表来删除?



2)将sudo添加到git和tar命令是必要的。



3)当安装opus和ffmpeg时,由于缺少写入权限,最终配置失败,因此./configure命令有许多错误消息。



无论如何,只是想我会将这些问题记录在帖子上,希望能够改进上面列出的步骤。


I had previously used OpenCV 2.4.5 with some certain configs and packages on Ubuntu 12.04.1 but had issues upgrading to OpenCV 2.4.6.1 on Ubuntu 12.04.2

I would like to share some ideas (a compilation of noteworthy information gathered from several sources including SO, ubuntu.org, asklinux.org and many other; and of course by trying several procedures)

Below is what eventually got me through.

NOTE: ensure you uninstall any previous installation of OpenCV, FFMpeg and other dependencies previously installed.

STEP 1 (install ffmpeg and dependencies)


# goto http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/
# download the latest stable opencv such as 2.4.6.1 (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.5/opencv-2.4.5.1.tar.gz/download) to current directory (such as home or ~/Document)
# cd /opt
# tar -xvf <path-to-download-folder>/OpenCV-2.4.6.1.tar.gz
# cd OpenCV-2.4.6.1
# create a foler under current dir (following previous step, this should be <opencv-dir>), called prepare
# cd prepare
# Copy the following script to gedit and save as install.sh to current dir, this should be <opencv-dir>/prepare
# Check corresponding url used in the script for latest versions of the package and replace as required
# Open terminal and navigate to location used above
# sudo chmod +x install.sh
# ./install


echo "Removing any pre-installed ffmpeg, x264, and other dependencies (not all the previously installed dependecies)"
sudo apt-get remove ffmpeg x264 libx264-dev libvpx-dev librtmp0 librtmp-dev libopencv-dev
sudo apt-get update

arch=$(uname -m)
if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
flag=0
else
flag=1
fi

echo "Installing Dependenices"
sudo apt-get install autoconf automake make g++ curl cmake bzip2 python unzip \
  build-essential checkinstall git git-core libass-dev libgpac-dev \
  libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \
  libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev

echo "downloading yasm (assembler used by x264 and FFmpeg)"
# use git or tarball (not both)
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzvf yasm-1.2.0.tar.gz
cd yasm-1.2.0

echo "installing yasm"
./configure
make
sudo make install
cd ..

echo 'READ NOTE BELOW which was extracted from http://wiki.serviio.org/doku.php?id=build_ffmpeg_linux'
echo 'New version of x264 contains by default support of OpenCL. If not installed or without sense (example Ubuntu 12.04LTS on VMWare) add to configure additional option --disable-opencl. Without this option ffmpeg could not be configured (ERROR: libx264 not found).'

echo "downloading x264 (H.264 video encoder)"
# use git or tarball (not both)
# git clone http://repo.or.cz/r/x264.git or
git clone git://git.videolan.org/x264.git
cd x264
# wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20130801-2245-stable.tar.bz2
# tar -xvjf x264-snapshot-20130801-2245-stable.tar.bz2
# cd x264-snapshot-20130801-2245-stable/

echo "Installing x264"
if [ $flag -eq 0 ]; then
./configure --enable-static --disable-opencl
else
./configure --enable-shared --enable-pic --disable-opencl
fi
make
sudo make install
cd ..

echo "downloading fdk-aac (AAC audio encoder)"
# use git or tarball (not both)
git clone --depth 1 git://github.com/mstorsjo/fdk-aac.git
cd fdk-aac

echo "installing fdk-aac"
autoreconf -fiv
./configure --disable-shared
make
sudo make install
cd ..

echo "installing libmp3lame-dev (MP3 audio encoder.)"
sudo apt-get install libmp3lame-dev

echo "downloading libopus (Opus audio decoder and encoder.)"
wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz
tar xzvf opus-1.0.3.tar.gz
cd opus-1.0.3

echo "installing libopus"
./configure --disable-shared
make
sudo make install
cd ..

echo "downloading libvpx VP8/VP9 video encoder and decoder)"
# use git or tarball (not both)
git clone --depth 1 http://git.chromium.org/webm/libvpx.git
cd libvpx
# wget http://webm.googlecode.com/files/libvpx-v1.1.0.tar.bz2 (this seems not to be update, but can still be used if the fedoraproject link below is not available))
# wget http://pkgs.fedoraproject.org/repo/pkgs/libvpx/libvpx-v1.2.0.tar.bz2/400d7c940c5f9d394893d42ae5f463e6/libvpx-v1.2.0.tar.bz2
# tar xvjf libvpx-v1.2.0.tar.bz2
# cd libvpx-v1.2.0

echo "installing libvpx"
./configure --disable-examples
make
sudo make install
cd ..

sudo ldconfig

echo "downloading ffmpeg"
# git clone http://repo.or.cz/r/ffmpeg.git
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg/
# wget http://ffmpeg.org/releases/ffmpeg-2.0.tar.bz2
# tar -xvjf ffmpeg-2.0.tar.bz2
# cd ffmpeg-2.0/

echo "installing ffmpeg" 
if [ $flag -eq 0 ]; then
./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx
else
./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx --enable-shared
fi

make
sudo make install
hash -r

cd .. # move up one level to prepare folder
cd .. # move up one level to opencv folder

echo "Checking to see if you're using your new ffmpeg"
ffmpeg 2>&1 | head -n1

sudo ldconfig

STEP 2 (Install OpenCV and necessary packages)

echo "Installing Dependenices"    
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev

echo "installing Video I/O libraries, support for Firewire video cameras and video streaming libraries"
sudo apt-get install libav-tools libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev v4l-utils v4l-conf

echo "installing the Python development environment and the Python Numerical library"
sudo apt-get install python-dev python-numpy

echo "installing the parallel code processing library (the Intel tbb library)"
sudo apt-get install libtbb-dev

echo "installing the Qt dev library"
sudo apt-get install libqt4-dev libgtk2.0-dev

echo "installing other dependencies (if need be it would upgrade current version of the packages)"
sudo apt-get install patch subversion ruby librtmp0 librtmp-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev libxvidcore-dev

echo installing optional packages"
sudo apt-get install libdc1394-utils libdc1394-22-dev libdc1394-22 libjpeg-dev libpng-dev libtiff-dev libjasper-dev

STEP 3 (run ldconfig)

# Open a new terminal window
# Open /etc/ld.so.conf and check, 
# if the paths "/usr/lib" and "/usr/local/lib" including the quote exist in the file. If not, add them manually or by
    sudo echo "/usr/local/lib" >> /etc/ld.so.conf
    sudo echo "/usr/lib" >> /etc/ld.so.conf
# execute the following
    sudo ldconfig

STEP 4a (Build & Install for OS Usage)

# still ensure you haven't close the new terminal window open in STEP 3
# execute the following
mkdir os_build
cd os_build
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_NEW_PYTHON_SUPPORT=ON -DINSTALL_PYTHON_EXAMPLES=ON -DWITH_TBB=ON -DWITH_V4L=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DWITH_QT=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_EIGEN=ON -DWITH_OPENEXR=ON ..

    make
    sudo make install

# add the following to user environment variable ~/.bashrc
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
    export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig
# execute the following
    sudo ldconfig
# start to use and enjoy opencv, it should have been install into any of these locations
#   /usr/local/include/opencv2, /usr/local/include/opencv, /usr/include/opencv, /usr/include/opencv2, /usr/local/share/opencv
#   /usr/local/share/OpenCV, /usr/share/opencv, /usr/share/OpenCV, /usr/local/bin/opencv*, /usr/local/lib/libopencv*

STEP 4b (Build for Java Usage): OPTIONAL

# still ensure you haven't close the new terminal window open in STEP 4
# execute the following
    cd ..
    mkdir java_build
    cd java_build
    cmake -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -DINSTALL_PYTHON_EXAMPLES=ON -DWITH_TBB=ON -DWITH_V4L=ON -DINSTALL_C_EXAMPLES=ON -DBUILD_EXAMPLES=ON -DWITH_QT=ON -DWITH_OPENGL=ON -DWITH_OPENCL=ON -DWITH_EIGEN=ON -DWITH_OPENEXR=ON ..

    make

# You can check the "java_build/bin" directory to locate the jar and libopencv_java.so file for your development
# As stated in the docs, the Java bindings dynamic library is all-sufficient, i.e. doesn’t depend on other OpenCV libs, but includes all the OpenCV code inside

STEP 5 (install v4l: Note: installing v4l-utils after opencv installation works for Ubuntu 12.04.2 & OpenCV 2.4.6.1)

# still ensure you haven't close the new terminal window open in STEP 3
# goto http://www.linuxtv.org/downloads/v4l-utils
# download the latest v4l such as v4l-utils-0.9.5.tar.bz2
# copy the downloaded file to the current terminal dir (following previous step, this should be <opencv-dir>/prepare)
# execute the following
    tar -xvjf v4l-utils-0.9.5.tar.bz2
    cd v4l-utils-0.9.5/
    ./configure
    make
    sudo make install
    cd ..
    cd .. # (to go to <opencv-dir>)
    sudo ldconfig

Worth Noting

# To check the path where opencv & other lib files are stored, do:


pkg-config --cflags opencv

    (output will come as)
    -I/usr/include/opencv



pkg-config --libs opencv

    (output will come as)
    -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ --ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann

# The above paths are needed to compile your opencv programs, as given in the next illustration.

# write a simple C program to test, by saving below program in a file named DisplayImage.c

#include <stdio.h>
    #include <opencv2/highgui/highgui.hpp>

    int main(int argc, char *argv[]) {
        IplImage* img=0; /* pointer to an image */
        printf("Hello\n");

        if(argv[1] != 0)
            img = cvLoadImage(argv[1], 0); // 1 for color
        else
            printf("Enter filename\n");

        if(img != 0) {
            cvNamedWindow("Display", CV_WINDOW_AUTOSIZE); // create a window
            cvShowImage("Display", img); // show image in window
            cvWaitKey(0); // wait until user hits a key
            cvDestroyWindow("Display");
        }
        else
            printf("File not found\n");

        return 0;
    }

# write a simple C++ program to test, by saving below program in a file named DisplayImage.cpp

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1], 1 );

  if( argc != 2 || !image.data )
    {
      printf( "No image data \n" );
      return -1;
    }

  namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
  imshow( "Display Image", image );

  waitKey(0);

  return 0;
}

# To compile & run :



g++ <filename: e.g. DisplayImage.c or DisplayImage.cpp> `pkg-config --cflags --libs opencv` && ./a.out img

or



g++ -I/usr/include/opencv -I/usr/local/include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree <filename: e.g. DisplayImage.c or DisplayImage.cpp> && ./a.out img

where "img" is the name of any image with extension within the same folder .
You should be able to see "Hello" and the image in a different window.

If this runs, Congrats! now you can run any C/C++ program with opencv lib.


# Now lets simplify the above big command by making a shortcut for it:
go to your local home directory(cd /home/) and open the .bashrc file using gedit(the file will be hidden). Append the following to the file:



alias gcv="g++ -I/usr/include/opencv -I/usr/local/include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree"

and save. Close the terminal and open it again.(as this process requires relogin of the terminal)

# Now, go to directory containing a sample program & do



gcv <filename: e.g. DisplayImage.c or DisplayImage.cpp> && ./a.out

or



gcv <filename: e.g. DisplayImage.c or DisplayImage.cpp>
    ./a.out input_img.jpg

As you can see the commands now become similar to $cc filename.c, $./a.out which are used normally for compiling and executing C/C++ programs.


Some ways to check whether all lib files are installed-

apt-cache search opencv

returns:

libcv-dev - Translation package for libcv-dev
libcv2.3 - computer vision library - libcv* translation package
libcvaux-dev - Translation package for libcvaux-dev
libcvaux2.3 - computer vision library - libcvaux translation package
libhighgui-dev - Translation package for libhighgui-dev
libhighgui2.3 - computer vision library - libhighgui translation package
libopencv-calib3d-dev - development files for libopencv-calib3d
libopencv-calib3d2.3 - computer vision Camera Calibration library
libopencv-contrib-dev - development files for libopencv-contrib
libopencv-contrib2.3 - computer vision contrib library
libopencv-core-dev - development files for libopencv-core
libopencv-core2.3 - computer vision core library
libopencv-dev - development files for opencv
libopencv-features2d-dev - development files for libopencv-features2d
libopencv-features2d2.3 - computer vision Feature Detection and Descriptor Extraction library
libopencv-flann-dev - development files for libopencv-flann
libopencv-flann2.3 - computer vision Clustering and Search in Multi-Dimensional spaces library
libopencv-gpu-dev - development files for libopencv-gpu
libopencv-gpu2.3 - computer vision GPU Processing library
libopencv-highgui-dev - development files for libopencv-highgui
libopencv-highgui2.3 - computer vision High-level GUI and Media I/O library
libopencv-imgproc-dev - development files for libopencv-imgproc
libopencv-imgproc2.3 - computer vision Image Processing library
libopencv-legacy-dev - development files for libopencv-legacy
libopencv-legacy2.3 - computer vision legacy library
libopencv-ml-dev - development files for libopencv-ml
libopencv-ml2.3 - computer vision Machine Learning library
libopencv-objdetect-dev - development files for libopencv-objdetect
libopencv-objdetect2.3 - computer vision Object Detection library
libopencv-video-dev - development files for libopencv-video
libopencv-video2.3 - computer vision Video analysis library
opencv-doc - OpenCV documentation and examples
python-opencv - Python bindings for the computer vision library

解决方案

Thanks for the information. I tried to run these commands but encountered several problems. I am using a brand new Ubuntu 12.04 install.

1) The first apt-get remove command asked me if I wanted to remove a lot of things that I wasn't comfortable removing, like LibreOffice. I didn't remove anything in this step, which I figured would be okay, since the only program I've installed is Java SDK and JRE. Why did you opt for such a large list of programs to remove?

2) Adding sudo to the git and tar commands was necessary.

3) When installing opus and ffmpeg, there were many error messages for the ./configure command because of a lack of permission for writing and ultimately the configurations failed.

Anyways, just thought I would log these problems on the post in the hopes that it will improve the procedure listed above.

这篇关于在Ubuntu 12.04.02上设置/安装OpenCV 2.4.6.1+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆