opencv学习记录(1)安装与配置

       fedora18下安装配置qt+opencv+ffmpge


        大三快完了,考试基本算是结束了,虽然决定了考研,但还是再多学点东西吧,不然复试和后面的学习中难免吃亏,现在对数字图像处理这个方向很感兴趣,之前也接触了linux QT arm,便删了win7重装fedora,希望可以借此机会打打基础。

       系统我选择的是fedora18,本来考虑到可能会遇到一些问题想用17,但是之前下在的17的dvd iso安装一直出问题,还是下在了fedora18,想着19也快出了,18应该不会出大乱子。未来可能还是会学习嵌入式相关的东西便还是选择了QT+opencv的组合。系统安装用的liveusb,fedora自家。遇到的问题主要有两个:

1.17的dvd iso文件烧到sd卡上安装的分区后会出现问题只能退出

2.用笔记本自带的读卡器安装也会出问题,甚至烧上ubuntu的livecd连引导都引导不了,换成读卡器以后就没问题了

        之后我先安装的QT,这个就从http://qt-project.org/网站下载,我是把qt library和creator分别下载下来后编译安装的现在想想可能直接安装那个一体的也没事,我主要是还不熟悉编译安装的过程经过这个安装也算熟悉了一遍,库用的qt4.7的,最新的版本编译到qt webit总是报错之前也遇到了不少错误(多为依赖包没有安装,找到相关的依赖就好了)但这个错误就是找不到怎么解决,也就放弃了,还是用回了最开始学习qt时用的qt4.7有了之前的经验倒是没有遇到什么问题我主要参考的这篇文章http://www.linuxidc.com/Linux/2011-03/33424.htm 大概流程也就是:

1.下载qt库

2.tar -zxvf qt-everywhere-opensource-src-4.7.3.tar.gz -C /opt

3../configure o是开源的版本 然后yes遵守gpl balabala协议

4.gmake&& gmake install

5.配置系统环境 修改/etc/profile 或者~/.bashrc文件,在最后添加

export PATH=/usr/local/Trolltech/Qt-4.7.3/bin:$PATH
export QTDIR=/usr/local/Trolltech/Qt-4.7.3
export MANPATH=$QTDIR/man:$MANPATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

6.在terminal测试一下 qmake 出来奇怪的东西就正常了

7.安装qtcreator 先修改一下文件的权限 chmod u+x 文件名  然后./文件名 就好了

安装后,要在里面设置qmake的位置才能编译(掩面…………开始一直找不到qmake在哪 其实之前设置系统环境就有设置了 就在path那里面。。)然后可以试着跑一下example里面的例子,成功的话就没问题了。

        然后安装opencv,这个真是蛋疼的一比阿,网上搜了一下安装的教程,查到了不少文章但是fedora下的没多少,大部分都是ubuntu(ps:用过一段时间ubuntu感觉用着没fedora习惯)反正都是linux就参考着来了,不过那一堆apt……我就无力了,依赖包都是自己手动慢慢搜的,当时也没考虑到要写一篇文章就没整理(抱歉了 以后再安什么一定记一下方便大家也方便自己,看到很多做opencv都会安ffmpeg,也就顺手安了(一顺手不要紧,直接搞了2天。。)不过我发现了这篇文章真是感激涕零阿,之前全都白安了,我是在最后安opencv的时候出的问题搜到的。。

转自http://blog.sina.com.cn/s/blog_641c14a9010189g1.html 复制如下做个记录

The Installation Procedure

To install and configure OpenCV 2.4.1, complete the followingsteps. The commands shown in each step can be copy and pasteddirectly into a Linux command line.

  1.  

  2. Remove any installed versions of ffmpeg and x264.

    sudo apt-get remove ffmpeg x264 libx264-dev

  3.  

  4. Get all the dependencies for x264 and ffmpeg.

    sudo apt-get update
    sudo apt-get install build-essential checkinstall git cmakelibfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-devlibopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-devlibvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-devtexi2html yasm zlib1g-dev

  5.  

  6. Download and install gstreamer.

    sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-devgstreamer0.10-tools gstreamer0.10-plugins-baselibgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-goodgstreamer0.10-plugins-ugly gstreamer0.10-plugins-badgstreamer0.10-ffmpeg

  7.  

  8. Download and install gtk.

    sudo apt-get install libgtk2.0-0 libgtk2.0-dev

  9.  

  10. Download and install libjpeg.

    sudo apt-get install libjpeg8 libjpeg8-dev

  11.  

  12. Create a directory to hold source code.

    cd ~
    mkdir src

  13.  

  14. Download and install install x264.
    1. Download a recent stable snapshot of x264from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/.The exact version does not seem to matter. To write this guide, Iused version x264-snapshot-20120528-2245-stable.tar.bz2, but I haveused previous versions too.

      cd ~/src

      wgetftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2

      tar xvf x264-snapshot-20120528-2245-stable.tar.bz2

      cd x264-snapshot-20120528-2245-stable

    2. Configure and build the x264 libraries.

      ./configure --enable-static
      make
      sudo make install

      IMPORTANT: If you are running a 64-bit version of Ubuntu, you mustconfigure x264 as shown in the following command:

      ./configure --enable-shared --enable-pic

      The -shared and -pic options might also be required when youcompile for some other architectures, such as ARM. You know youneed these options if you get the following error when compilingOpenCV:

      [ 25%] Building CXX objectmodules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o
      Linking CXX shared library ../../lib/libopencv_highgui.so
      /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocationR_X86_64_32S against `av_destruct_packet' can not be used whenmaking a shared object; recompile with -fPIC
      /usr/local/lib/libavcodec.a: could not read symbols: Badvalue

       

  15.  

  16. Download and install install ffmpeg.
    1. Download ffmpeg version 0.11.x from http://ffmpeg.org/download.html.

      cd ~/src
      wget http://ffmpeg.org/releases/ffmpeg-0.11.tar.bz2
      tar xvf ffmpeg-0.11.tar.bz2
      cd ffmpeg-0.11

    2. Configure and build ffmpeg.

      ./configure --enable-gpl --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

      make
      sudo make install

      IMPORTANT: Just like with x264 in the previous step, you mustconfigure ffmpeg with the -shared option if you are running a64-bit version of Ubuntu or some other architectures, such as ARM.The -pic option is not necessary for ffmpeg.

      ./configure --enable-gpl --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-shared

  17.  

  18. Download and install install a recent version of v4l (video forlinux) from http://www.linuxtv.org/downloads/v4l-utils/.For this guide I used version 0.8.8.

    cd ~/src

    wgethttp://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.8.tar.bz2

    tar xvf v4l-utils-0.8.8.tar.bz2
    cd v4l-utils-0.8.8
    make
    sudo make install

  19.  

  20. Download and install install OpenCV 2.4.1.
    1. Download OpenCV version 2.4.1 from http://sourceforge.net/projects/opencvlibrary/files/

      cd ~/src

      wgethttp://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.tar.bz2

      tar xvf OpenCV-2.4.1.tar.bz2

    2. Create a new build directory and run cmake:

      cd OpenCV-2.4.1/
      mkdir build
      cd build
      cmake -D CMAKE_BUILD_TYPE=RELEASE ..

    3. Verify that the output of cmake includes the following text:
      • found gstreamer-base-0.10
      • GTK+ 2.x: YES
      • FFMPEG: YES
      • GStreamer: YES
      • V4L/V4L2: Using libv4l
    4. Build and install OpenCV.

      make
      sudo make install

  21.  

  22. Configure Linux.
    1. Tell linux where the shared libraries for OpenCV are located byentering the following shell command:

      export LD_LIBRARY_PATH=/usr/local/lib

      Add the command to your .bashrc file so that you don’t have toenter every time your start a new terminal.

      Alternatively, you can configure the system wide library searchpath. Using your favorite editor, add a single line containing thetext /usr/local/lib tothe end of a file named/etc/ld.so.conf.d/opencv.conf.In the standard Ubuntu install, the opencv.conf file does notexist; you need to create it. Using vi, for example, enter thefollowing commands:

      sudo vi /etc/ld.so.conf.d/opencv.conf
      G
      o
      /usr/local/lib
      <Esc>
      :wq!

      After editing the opencv.conf file, enter the followingcommand:

      sudo ldconfig /etc/ld.so.conf

      .

    2. Using your favorite editor, add the following two lines to theend of /etc/bash.bashrc:

      PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
      export PKG_CONFIG_PATH

 

After completing the previous steps, your system should be ready tocompile code that uses the OpenCV libraries. The following exampleshows one way to compile code for OpenCV:

g++ `pkg-config opencv --cflags` my_code.cpp  -omy_code `pkg-config opencv--libs` 

 建议不要全部照做,容易因为缺软件出错,最好在root下先装好以下软件(来自旧版opencv官网http://opencv.willowgarage.com/wiki/InstallGuide: Debian

 

 

apt-get install build-essential

apt-get install cmake

apt-get install pkg-config

apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3

apt-get install libpnglite-dev libpngwriter0-devlibpngwriter0c2

apt-get install zlib1g-dbg zlib1g zlib1g-dev

apt-get install libjasper-dev libjasper-runtime libjasper1

apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2libtiff-tools

apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog

apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52libavformat-dev

apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev

apt-get install libxine1-ffmpeg  libxine-devlibxine1-bin

apt-get install libunicap2 libunicap2-dev

apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils

apt-get install swig

apt-get install libv4l-0 libv4l-dev

apt-get install python-numpy

以下可选

 

If you also want to use OpenCV from Python, add this:

    apt-get install libpython2.6python-dev python2.6-dev  # Only if you want touse python

If your system has trouble with building "libjpeg.so", you may needto build it manually, or try this:

    apt-get install libjpeg-progslibjpeg-dev

On Ubuntu 10.10 this apt-get was needed to recognize gstream-appand gstreamer-vid development headers

    apt-get installlibgstreamer-plugins-base0.10-dev

反正我是都装上了,就不容易有错。

另外,用cmake时因为预设的有cuda,可能不需要,如果不熟悉如何更改cmake文件的话就可以安装cmake-gui,之后图形界面操作。

可能的错误:

1. fatal:Not a git repository (or any of the parent directories):.git

解决方法

 

git init 
git add . 
git commit -m 'Initial commit'

2. Traceback (most recent call last):File"<string>", line 1, in<module>ImportError: No module namednumpy.distutils

或者ImportError: No module named numpy.distutils

原因:没装python-numpy

3. 最无语的ld: cannot find -lcv(以及 -lhighgui, -lcxcore等等)

 原因:找不到库函数libcv, libhighgui,libcoxe

我的环境是eclipse,是因为新版opencv的一些新函数所以进行了升级

但是筒子们注意了,现在(2.4.1)函数库的名字都改成libopencv_xx了,所以应该写成opencv_highgui等。

在网上找了链接错误啊之类的原因,折腾了一天,才发现原来已经配置好了,所以下次不要过于依赖软件,先用命令行检查:

g++ `pkg-configopencv --cflags` my_code.cpp  -o my_code`pkg-config opencv --libs`

当然自己先写好my_code.cpp,如果生成了可执行文件,说明opencv配置已经成功了。

用这个安装过程是正确的中间也碰到了些问题,能记住的主要有参考http://blog.csdn.net/jszj/article/details/7589566


libavcodec/x86/h264_qpel_mmx.c: Assembler messages:
libavcodec/x86/h264_qpel_mmx.c:1294: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:1294: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:1298: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:1298: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
libavcodec/x86/h264_qpel_mmx.c:964: Error: operand type mismatch for `cmp'
make: *** [libavcodec/x86/dsputil_mmx.o] Error 1

在baidu上搜索不到,在bing上搜索到 http://comments.gmane.org/gmane.comp.handhelds.openembedded/51922,上面列举了多个bug,其中有一个就是这个,点它后面的continue查看这个bug的完整信息,网址为 http://permalink.gmane.org/gmane.comp.handhelds.openembedded/51954,实际上通过补丁解决这个问题的,这里还按照上次的补丁做法,直接用gedit打开这个文件来修改,但这次有点麻烦,本来提示出错的行是1294、1298、964,但实际上这个文件只有1201行!
猜测应该是由于宏定义引起的行数变化,没有办法,只有完全依照这个网上的方法来修改了。文件修改了4个位置,都是把“g”改成了“rm”

还有一个不太清了,反正最后是用了 yum updata 什么什么 用google搜英文的网站找到解决办法……貌似是fedora特有的错误。反正fedora下多用yum就好了不过我最后安装opencv时cmake那个文档里面qt4.x依然是no,当时还怕用qt编译不了(现在已经学了一点opencv了,跑程序没什么问题)安装和环境配置基本上就到这里了,25后软件设计师考试(保佑阿!!!)后面的学习基本上就围绕着opencv和考研进行了!!一定加油!!

原创文章,欢迎转载,转载请注明:http://blog.csdn.net/iamsure001

作者:Ashawn

小菜鸟学it!!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值