在ORB SLAM中,通过四叉树的方式存储关键点,使得图像上特征点分布均匀,便于追踪。此次实验分别用opencv接口和ORB SLAM实现特征点的提取,效果图如下:
实现程序:
#include <iostream> //#include <opencv2/core/core.hpp> //#include <opencv2/features2d/features2d.hpp> //#include <opencv2/highgui/highgui.hpp> #include <opencv2/opencv.hpp> #include "ORBextractor.h" using namespace std; using namespace cv; int main ( int argc, char** argv ) { //-- 读取图像 Mat img_1 = imread ( "1.png" ); Mat mImGray=img_1; Mat outimg1,outimg2;//输出图像 cvtColor(mImGray,mImGray,CV_RGB2GRAY);//转换为灰度图 //opencv中接口函数 std::vector<KeyPoint> keypoints_1,keypoints_2; Mat descriptors_1,descriptors_2; Ptr<FeatureDetector> detector = ORB::create(); Ptr<DescriptorExtractor> descriptor = ORB::create(); detector->detect ( mImGray,keypoints_1 ); descriptor->compute ( mImGray, keypoints_1, descriptors_1 ); drawKeypoints( img_1, keypoints_1, outimg1, Scalar::all(-1), DrawMatchesFlags::DEFAULT ); imshow("opencv提取ORB特征点",outimg1); //调用ORB SLAM中特征提取函数 ORBextractor* mpIniORBextractor; mpIniORBextractor = new ORBextractor(500,1.2,8,20,10); (*mpIniORBextractor)(mImGray,cv::Mat(),keypoints_2,descriptors_2 ) ; drawKeypoints( img_1, keypoints_2, outimg2, Scalar::all(-1), DrawMatchesFlags::DEFAULT ); imshow("ORB SLAM提取ORB特征点",outimg2); waitKey(0); return 0; }
CMakeList.txt:
cmake_minimum_required(VERSION 3.13) project(keypoint111) set(CMAKE_CXX_STANDARD 11) find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) aux_source_directory(. DIR_SRCS)#当有多个源文件时,此命令查找当前目录下的所有源文件 #注意.后面有一个空格,将所有源文件的名称保存到DIR_SRCS中 add_executable(keypoint111 ${DIR_SRCS}) target_link_libraries(keypoint111 ${OpenCV_LIBS})
注意:CMake会将当前源文件的文件名赋值给DIR_SRCS,再指示该变量中的源文件需要编译成一个名为keypoint11的可执行文件。
ORB SLAM中特征提取程序分析: