OpenCV 3.0.0 alpha compile by gcc cmake

1.prepare

更新
sudo apt-get update && apt-get upgrade

安裝依賴庫
apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant libvtk5-qt4-dev

2.Get SourceCode of opencv from git

cd ~/<my_working _directory>
git clone https://github.com/Itseez/opencv.git

like me ~/github/opencv

3.compile by cmake

mkdir build
cd build
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_IPP=OFF -D CMAKE_INSTALL_PREFIX=/usr ..

不能出現error,若出現可以嘗試修改
INSTALL_C_EXAMPLES=OFF

然後

sudo make
sudo make install

4.test project

4.1 by cmake and gcc

4.1.1 edit /etc/profile

修改環境變量PKG_CONFIG_PATH:
在/etc/profile中寫入export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:your_opencv_cmake_path/unix-install

修改動態鏈接庫查找路徑: 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:your_install_path/lib/

vim /etc/profile




其中,your_opencv_cmake_path就是用來編譯opencv的路徑,如上示例中是~/github/opencv/build

動態鏈接庫在安裝目錄下,此處的安裝目錄爲/usr

4.1.2 creare test sample

新建下述代碼DisplayImage.cpp

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

using namespace cv;

int main(int argc, char** argv )
{
    if ( argc != 2 )
    {
        printf("usage: DisplayImage.out <Image_Path>\n");
        return -1;
    }

    Mat image;
    image = imread( argv[1], 1 );

    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    //namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", image);

    waitKey(0);

    return 0;
}

4.1.3 create CMakeLists.txt

在*.cpp所在目錄下,新建CMakeLists.txt,並寫入

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
set(OpenCV_DIR /home/peijian/github/opencv/build)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

4.1.4 run

cmake .
make
./DisplayImage lena.jpg

4.2 only gcc

c++ file
 
g++ `pkg-config --cflags opencv` -o DisplayImage DisplayImage.c `pkg-config --libs opencv`

c file
 
g++ `pkg-config --cflags opencv` -o cvtest cvtest.c `pkg-config --libs opencv`

注:

###########################################################

########注意:g++ 後邊那個東西是 ` ,就是ESC下邊那個鍵##########

###########################################################

參考資料



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章