Skip to content

Commit

Permalink
add distribute orb feature
Browse files Browse the repository at this point in the history
  • Loading branch information
weihaoysgs committed Apr 6, 2024
1 parent 7d9e2c6 commit a500d90
Show file tree
Hide file tree
Showing 6 changed files with 1,303 additions and 0 deletions.
4 changes: 4 additions & 0 deletions feat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
add_library(feature_extraction
orb/orb_feature.cc
harris/harris.cc
orb_slam/orbpattern.cpp
orb_slam/orbextractor.cpp
)
add_library(feature_tracking
optical_flow/lkpyramid.cc
Expand All @@ -11,6 +13,8 @@ add_executable(harris_test example/harris_test.cc)
target_link_libraries(harris_test feature_extraction ${THIRD_PARTY_LIBS} ${OpenCV_LIBS})
add_executable(orb_test example/orb_test.cc)
target_link_libraries(orb_test feature_extraction ${THIRD_PARTY_LIBS} ${OpenCV_LIBS})
add_executable(orb_slam_feat_test example/orbslam_feat_test.cc)
target_link_libraries(orb_slam_feat_test feature_extraction feature_tracking ${THIRD_PARTY_LIBS} ${OpenCV_LIBS})

add_executable(lk_optical_flow_test example/lk_optical_flow_test.cc)
target_link_libraries(lk_optical_flow_test feature_extraction feature_tracking ${THIRD_PARTY_LIBS} ${OpenCV_LIBS})
70 changes: 70 additions & 0 deletions feat/example/orbslam_feat_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
// Everyone is permitted to copy and distribute verbatim copies
// of this license document, but changing it is not allowed.
// This file is part of vio-hello-world Copyright (C) 2023 ZJU
// You should have received a copy of the GNU General Public License
// along with vio-hello-world. If not, see <https://www.gnu.org/licenses/>.
// Author: weihao([email protected]), M.S at Zhejiang University

#include "common/draw_utils.h"
#include "common/wall_time.h"
#include "feat/orb/orb_feature.h"
#include "feat/orb_slam/orbextractor.hpp"
#include "gflags/gflags.h"
#include "glog/logging.h"

DEFINE_string( image_path, "../feat/data/euroc01.png", "image file path" );
DEFINE_int32( max_kps, 500, "max kps" );

cv::Mat ORBImpl( const cv::Mat& image ) {
auto orb = feat::ORB::create( FLAGS_max_kps );
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
cv::Mat roi( image.size(), CV_8UC1, cv::Scalar( 255 ) );

com::EvaluateAndCall( [&]() { orb->detectAndCompute( image, roi, keypoints, descriptors ); },
"ORBImpl", 20 );

return com::DrawKeyPoints( image, keypoints, "" );
}

cv::Mat OpenCVORB( const cv::Mat& image ) {
auto orb = cv::ORB::create( FLAGS_max_kps );
std::vector<cv::KeyPoint> keypoints;
cv::Mat descriptors;
cv::Mat roi( image.size(), CV_8UC1, cv::Scalar( 255 ) );

com::EvaluateAndCall( [&]() { orb->detectAndCompute( image, roi, keypoints, descriptors ); },
"OpenCVORB", 20 );

return com::DrawKeyPoints( image, keypoints, "" );
}

cv::Mat ORB_SLAM_Feat( const cv::Mat& image ) {
std::shared_ptr<feat::ORBextractor> orb_extractor_ = nullptr;
orb_extractor_.reset( new feat::ORBextractor( FLAGS_max_kps, 1.2, 8, 20, 7 ) );
std::vector<cv::KeyPoint> kps;
cv::Mat mask( image.size(), CV_8UC1, cv::Scalar::all( 255 ) );
com::EvaluateAndCall( [&]() { orb_extractor_->Detect( image, mask, kps ); }, "ORB-SLAM Feat",
20 );
return com::DrawKeyPoints( image, kps, "" );
}

int main( int argc, char** argv ) {
::google::InitGoogleLogging( "test_orb_feature" );
FLAGS_stderrthreshold = google::INFO;
::google::ParseCommandLineFlags( &argc, &argv, true );

cv::Mat gray_image = cv::imread( FLAGS_image_path, cv::IMREAD_GRAYSCALE );
LOG_ASSERT( gray_image.empty() == false ) << " Image is empty, please check you image path.";

cv::Mat orb_impl_result = ORBImpl( gray_image );
cv::Mat cv_impl_result = OpenCVORB( gray_image );
cv::Mat orbslam_feat_result = ORB_SLAM_Feat( gray_image );

cv::imshow( "ORB Impl", orb_impl_result );
cv::imshow( "ORBSLAM Feat Impl", orbslam_feat_result );
cv::imshow( "OpenCV Impl", cv_impl_result );
cv::waitKey( 0 );
return 0;
}
Loading

0 comments on commit a500d90

Please sign in to comment.