Opencv Linux

1. Get sourcecode download OpenCV_xx.tar

   tar xvf ~/Downloads/OpenCV-2.3.1a.tar.bz2

   cd  OpenCV-2.3.1

 #sudo apt-get installbuild-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

 #./configure在opencv 2.1之后不再采用,可以使用cmake去配置config

 # svn co https://code.ros.org/svn/opencv/trunk 


2. configure opencv Cmake&&GCC

  • For example, if you downloaded the project to ~/projects/opencv, you can do the following:
    •    cd ~/projects/opencv # the directory containing INSTALL, CMakeLists.txt etc.
         mkdir release
         cd release
         cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..

    Note: ..上一级目录

    3. compile using gcc

     cd release

     make install

        notes:

           3.1 download ffmpeg and build

                 svn co svn://svn.mplayerhq.hu//ffmpeg/trunk ffmpeg

                 ./configure --enable-shared --disable-yasm

                  make

                 sudo make install

  • Now you have to configure the library. First, open the opencv.conf file with the following code:

    sudo gedit /etc/ld.so.conf.d/opencv.conf

    Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

    /usr/local/lib

    Run the following code to configure the library:

    sudo ldconfig

    Now you have to open another file:

    sudo gedit /etc/bash.bashrc

    Add these two lines at the end of the file and save it:

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

    4. Test example

      g++ `pkg-config opencv --libs --cflags opencv` drawing.c -o drawing
    Note: 1.  ``这里不是分号,而是数字1键左边的符合。

              2.   sudo apt-get install libgtk2.0-dev pkg-config


    build_all.sh

    #!/bin/sh


    if [ $# -gt 0 ] ; then
            base=`basename $1 .c`
            echo "compiling $base"
            gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
    else
            for i in *.c; do
                echo "compiling $i"
                gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
            done
            for i in *.cpp; do
                echo "compiling $i"
                g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
            done
    fi

     

    (原)error while loading shared libraries解决方法

    撰写于 2012 年 04 月 01 日 | 分类 :Opencv | 7 条评论

    今天第二次在ubuntu下配置opencv的开发环境,编译程序时出现error while loading shared libraries: libopencv_core.so.2.3: cannot open shared object file: No such file or directory的错误。

    原因:出现这类错误表示,系统不知道xxx.so放在哪个目录下,这时候就要在/etc/ld.so.conf中加入xxx.so所在的目录。

    解决方法:在/etc/ld.so.conf中加入/usr/local/lib这一行,保存之后,再运行:/sbin/ldconfig –v更新一下配置即可。

    终端里运行:sudo vi /etc/ld.so.conf
    加入:/usr/local/lib这一行
    保存,退出,终端里运行:sudo /sbin/ldconfig -v
    

    这样,就可以编译了!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值