1下载openCV源码
openCV源码下载地址:http://opencv.org/
2安装所需软件包
cmake build-essential libgtk2.0-dev
3解压源码
4配置openCV
进入源码根目录执行:cmake .
也可以用cmake-gui进行图像界面配置
5进行编译
sudo make
6安装openCV
sudo make install
4、测试opencv
1) 创建工作目录
mkdir ~/opencv-lena
cd ~/opencv-lena
gedit DisplayImage.cpp
2) 编辑如下代码
#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;
}
3) 创建CMake编译文件
gedit CMakeLists.txt
写入如下内容
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
4) 编译
cd ~/opencv-lena
cmake .
make
5) 执行
此时opencv-lena文件夹中已经产生了可执行文件DisplayImage,下载lena.jpg放在opencv-lena下,运行
./DisplayImage lena.jpg
6) 结果
时间: 2024-12-28 08:14:00