求助Ubuntu下安装opencv3.1.0
展开全部
opencv编译安装
编译环境安装:
[plain] view plain copy
sudo apt-get install build-essential
必需包安装:
[plain] view plain copy
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
可选包安装:
[plain] view plain copy
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
opencv下载:
稳定版
[plain] view plain copy
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
github源代码
[plain] view plain copy
git clone git://github.com/Itseez/opencv.git
创建编译的临时目录:
[plain] view plain copy
cd ~/opencv
mkdir build
cd build
注意: 这里假设opencv解压开的或者从github获取的源代码目录在用户主目录下。
生成cmake编译配置:
[plain] view plain copy
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
编译:
[plain] view plain copy
make -j4 # runs 4 jobs in parallel
安装opencv:
[plain] view plain copy
sudo make install
运行测试:
[plain] view plain copy
git clone https://github.com/Itseez/opencv_extra.git
OPENCV_TEST_DATA_PATH=~/opencv_extra
~/opencv/build/bin/opencv_test_core
一个例子:
首先创建一个目录 test,并进入目录:
[plain] view plain copy
mkdir test
cd test
其次,创建文件 DisplayImage.cpp 如下:
[plain] view plain copy
#include <stdio.h>
#include <opencv2/opencv.hpp>
usingnamespacecv;
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);
return0;
}
接着,创建cmake配置文件 CMakeLists.txt,如下:
[plain] view plain copy
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
最后运行:
[plain] view plain copy
./DisplayImage psu.jpg
#随便一张图片都行
编译环境安装:
[plain] view plain copy
sudo apt-get install build-essential
必需包安装:
[plain] view plain copy
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
可选包安装:
[plain] view plain copy
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
opencv下载:
稳定版
[plain] view plain copy
wget https://github.com/Itseez/opencv/archive/3.1.0.zip
github源代码
[plain] view plain copy
git clone git://github.com/Itseez/opencv.git
创建编译的临时目录:
[plain] view plain copy
cd ~/opencv
mkdir build
cd build
注意: 这里假设opencv解压开的或者从github获取的源代码目录在用户主目录下。
生成cmake编译配置:
[plain] view plain copy
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
编译:
[plain] view plain copy
make -j4 # runs 4 jobs in parallel
安装opencv:
[plain] view plain copy
sudo make install
运行测试:
[plain] view plain copy
git clone https://github.com/Itseez/opencv_extra.git
OPENCV_TEST_DATA_PATH=~/opencv_extra
~/opencv/build/bin/opencv_test_core
一个例子:
首先创建一个目录 test,并进入目录:
[plain] view plain copy
mkdir test
cd test
其次,创建文件 DisplayImage.cpp 如下:
[plain] view plain copy
#include <stdio.h>
#include <opencv2/opencv.hpp>
usingnamespacecv;
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);
return0;
}
接着,创建cmake配置文件 CMakeLists.txt,如下:
[plain] view plain copy
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
最后运行:
[plain] view plain copy
./DisplayImage psu.jpg
#随便一张图片都行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询