ubuntu 16.04源码编译OpenCV教程 | compile opencv on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/15f5c3e8/,欢迎阅读!
compile opencv on ubuntu 16.04
Series
- Part 1: compile opencv on ubuntu 16.04
- Part 2: compile opencv with CUDA support on windows 10
- Part 3: opencv mat for loop
- Part 4: speed up opencv image processing with openmp
Guide
requirements:
- ubuntu: 16.04
- opencv: 3.3.0
install dependencies
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install cmake-gui
compile
git clone https://github.com/opencv/opencv.git
wget https://github.com/opencv/opencv/archive/3.1.0.zip
cd opencv-3.1.0
mkdir build
cd build && cmake-gui ..
# may take several minutes
sudo make -j8
# install to /usr/local/bin
sudo make install
check version
opencv_version
3.3.0
python cv2
python
>>> import cv2
>>> cv2.__version__
pip install opencv
workon py3
pip install opencv-contrib-python
python
>import cv2
>cv2.__version__
'3.3.0'
for virtualenv, see python virtualenv tutorial
opencv samples
cd samples
cmake .
make
Example
Code
#include <iostream>
using namespace std;
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
int main()
{
Mat image = imread("../image/cat.jpg",0);
imshow("image",image);
waitKey(0);
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.8)
project(demo)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc features2d calib3d)
include_directories(${OpenCV_INCLUDE_DIRS})
message( [opencv] ${OpenCV_INCLUDE_DIRS} )
message( [opencv] ${${OpenCV_LIBS}} )
message( [opencv] ${${OpenCV_LIBRARIES}} )
add_executable(${PROJECT_NAME}
demo.cpp
)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES})
Reference
- Guide to compile and use opencv with CUDA support on windows 10
- opencv with openmp
- opencv WITH_OPENMP
History
- 20180919: created.
Copyright
- Post author: kezunlin
- Post link: https://kezunlin.me/post/15f5c3e8/
- Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.