看看http://blog.csdn.net/llp1992/article/details/50066983
sudo apt-get install libgtk2.0-dev pkg-config
安装opencv
去opencv官网(http://opencv.org/downloads.html)下载linux版本的opencv压缩包,此处下载的opencv3.1版本的。
unzip opencv-3.1.0.zip
cd ~/ opencv-3.1.0
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
2.测试opencv
mkdir ~/opencv-test
cd ~/opencv-test
gedit DisplayImage.cpp
//DisplayImage.cpp
#include
#include
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out \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;
}
创建CMake编译文件
gedit CMakeLists.txt
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} )
编译
cd ~/opencv-test
cmake .
make
执行
此时opencv-test文件夹中已经产生了可执行文件DisplayImage,随便从网上下载一张图片放在opencv-test文件夹下,此处下载了opencv.jpg,然后运行
./DisplayImage opencv.jpg
安装python的opencv库
sudo apt-get install python-opencv
sudo apt-get install python-numpy
#coding=utf-8
import cv2
img=cv2.imread("9-14-8.jpg")
"""
cv2.namedWindow("src")
cv2.imshow("src",img)
cv2.waitKey(0)
"""
cv2.imwrite("1.jpg",img)