Series
Guide
requirements:
- ubuntu: 16.04
- opencv: 3.3.0
install dependencies
1 2 3 4 5
| 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
1 2 3 4 5 6 7 8 9 10 11 12
| 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 ..
sudo make -j8
sudo make install
|
check version
python cv2
1 2 3
| python >>> import cv2 >>> cv2.__version__
|
pip install opencv
1 2 3 4 5 6 7
| workon py3 pip install opencv-contrib-python
python >import cv2 >cv2.__version__ '3.3.0'
|
for virtualenv, see python virtualenv tutorial
opencv samples
Example
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| cmake_minimum_required(VERSION 2.8.8)
project(demo)
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
History