概述
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++ fileg++ `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下边那个键##########
###########################################################
参考资料
【1】
OpenCV在linux平台的编译、安装和使用
【2】
Installing OpenCV 3.0.0 alpha in Ubuntu
【3】
Using OpenCV with gcc and CMake
【4】
Installation in Linux
【5】
Ubuntu修改环境变量
【6】
Win8(win7) x64位OS + VS2012 + OpenCV2.4.5 + CMake2.8 + TBB42自己编译OpenCV
最后
以上就是失眠宝贝为你收集整理的OpenCV 3.0.0 alpha compile by gcc cmake的全部内容,希望文章能够帮你解决OpenCV 3.0.0 alpha compile by gcc cmake所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复