Opencv Linux

    技术2025-08-27  16

    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)