预备包
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
安装
- 在github上搜索opencv源代码,并确保系统中有g++以及cmake,至少6G硬盘容量。
- 在解压根目录 mkdir build 然后 cd build
- cmake -DOPENCV_EXTRA_MODULES_PATH="path to opencv_contrib/modules/" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. (如有cache删除)
- make -j7
- sudo make install
使用
创建main.cpp
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img=imread("0.jpg");
imshow("demo", img);
waitKey(0);
return 0;
}
创建CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(demo)
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( demo main.cpp )
target_link_libraries( demo ${OpenCV_LIBS})
cmake . 然后 make 然后 ./demo 运行
如果运行有问题,按照英文提示安装所需库
默认设置会自动安装系统python最高版本的扩展