OpenCV3.1 SIFT使用
OpenCV3对OpenCV的模块进行了调整,将开发中与nofree模块放在 了OpenCV_contrib中(包含SIFT),gitHub上的官方项目分成了两个,opencv 与 opencv_contrib。所以,要使用sift接口需在opencv3.1基础上,再安装opencv_contrib。本文主要记录如何安装opencv_contrib,配置Xcode,sift接口的用法。
环境:OSX + Xcode + OpenCV3.1
install opencv_contrib
- download contrib source code , follow README.md to install
$ cd$ cmake -DOPENCV_EXTRA_MODULES_PATH= /modules $ make -j5$ sudo make install
Where <opencv_build_directory>
and <opencv_source_directory>
is directory in opencv3.1
configuration Xcode
like
pro_name Build Setting > Search Paths
- /usr/local/lib
- /usr/local/include
pro_name Build Setting >Other Linker Flags
- -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lippicv -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
sample of sift
sample in (souce_dir)/samples/cpp/tutorial_code/xfeatures2D/LATCH_match.cpp or bellow
#include "opencv2/xfeatures2d.hpp"// // now, you can no more create an instance on the 'stack', like in the tutorial// (yea, noticed for a fix/pr).// you will have to use cv::Ptr all the way down://cv::Ptr
f2d = xfeatures2d::SIFT::create();//cv::Ptr f2d = xfeatures2d::SURF::create();//cv::Ptr f2d = ORB::create();// you get the picture, i hope..//-- Step 1: Detect the keypoints:std::vector keypoints_1, keypoints_2; f2d->detect( img_1, keypoints_1 );f2d->detect( img_2, keypoints_2 );//-- Step 2: Calculate descriptors (feature vectors) Mat descriptors_1, descriptors_2; f2d->compute( img_1, keypoints_1, descriptors_1 );f2d->compute( img_2, keypoints_2, descriptors_2 );//-- Step 3: Matching descriptor vectors using BFMatcher :BFMatcher matcher;std::vector< DMatch > matches;matcher.match( descriptors_1, descriptors_2, matches );
References