OpenCV 3.1 Install
# References
http://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html#gsc.tab=0
http://blog.yucchiy.com/2014/10/18/install-opencv3-with-contrib/
1. Required Packages
- GCC 4.4.x or later
- CMake 2.8.7 or higher
- Git
- GTK+2.x or higher, including headers (libgtk2.0-dev)
- pkg-config
- Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
- ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
- [optional] libtbb2 libtbb-dev
- [optional] libdc1394 2.x
- [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
[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
|
2. Getting OpenCV Source Code
OpenCV 홈페이지(http://opencv.org/downloads.html)에서 소스코드를 다운로드 하는 방법도 있고,
Git repository(https://github.com/Itseez/opencv)를 이용하는 방법도 있다.
<my_working_directory>는 opencv파일의 저장에 사용할 적절한 경로를 적어주면 된다.
$ cd ~/<my_working_directory> $ git clone https://github.com/Itseez/opencv.git $ git clone https://github.com/Itseez/opencv_contrib.git |
* OpenCV 3.0이후 버전에서는
opencv2.4에서 nonfree에 있던 내용들이 opencv에는 포함되어 있지 않고
opencv_contrib의 module내에 있기 때문에 SIFT, SURF와 같은 알고리즘을 이용하기 위해서는 별도로 다운로드 및 설치가 필요함.
3. Building OpenCV from Source using CMake
opencv_contrib가 저장되어 있는 경로에 맞도록
-DOPENCV_EXTRA_MODULES_PATH="opencv_contrib의 경로"를 넣어줘야 한다.
$ cd opencv $ mkdir build && cd build $ cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules .. $ make -j5 $ sudo make install |
4. Let's Start Coding!
이제 OpenCV를 이용해서 코딩을 하면 된다!
간단한 예제를 하나 확인하는 것으로 마치겠습니다.
# SURF 특징 추출 및 추출된 특징의 display
Source Code (main.cpp)
#include <iostream> #include "opencv2/core.hpp" #include "opencv2/features2d.hpp" #include "opencv2/xfeatures2d/nonfree.hpp" #include "opencv2/highgui.hpp" using namespace cv; using namespace cv::xfeatures2d; void readme(); int main (int argc, char** argv) { if (argc != 3) { readme (); return -1; } Mat img_1 = imread (argv[1], IMREAD_GRAYSCALE); Mat img_2 = imread (argv[2], IMREAD_GRAYSCALE); if (!img_1.data || !img_2.data) { std::cout << "--(!) Error reading images " << std::endl; } // -- Step 1: Detect the keypoints using SURF Detector int minHessian = 400; Ptr<SURF> detector = SURF::create( minHessian ); std::vector<KeyPoint> keypoints_1, keypoints_2; detector->detect (img_1, keypoints_1); detector->detect (img_2, keypoints_2); // -- Draw Keypoints Mat img_keypoints_1; Mat img_keypoints_2; drawKeypoints (img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT ); drawKeypoints (img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT ); // -- Show detected (drawn) keypoints imshow ("Keypoints 1", img_keypoints_1); imshow ("Keypoints 2", img_keypoints_2); waitKey(0); return 0; } void readme() { std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; } |
CMakeLists.txt
cmake_minimum_required ( VERSION 2.8 ) project ( opencv_example ) find_package ( OpenCV REQUIRED ) include_directories ( ${OpenCV_INCLUDE_DIRS} ) add_executable ( main main.cpp ) target_link_libraries ( main ${OpenCV_LIBS} ) |
Results
|
|