37 #ifndef ESTIMATION_INTERNAL_H_
38 #define ESTIMATION_INTERNAL_H_
43 #include <opencv2/core/utility.hpp>
44 #include <opencv2/core/version.hpp>
45 #include <opencv2/features2d.hpp>
46 #include <opencv2/imgcodecs.hpp>
47 #include <opencv2/stitching/detail/matchers.hpp>
49 #ifdef HAVE_OPENCV_XFEATURES2D
50 #include <opencv2/xfeatures2d/nonfree.hpp>
57 #if CV_VERSION_MAJOR >= 4
63 return cv::AKAZE::create();
65 return cv::ORB::create();
67 #ifdef HAVE_OPENCV_XFEATURES2D
68 return xfeatures2d::SURF::create();
70 return cv::AKAZE::create();
78 #else // (CV_VERSION_MAJOR < 4)
80 static inline cv::Ptr<cv::detail::FeaturesFinder>
85 return cv::makePtr<cv::detail::AKAZEFeaturesFinder>();
87 return cv::makePtr<cv::detail::OrbFeaturesFinder>();
89 return cv::makePtr<cv::detail::SurfFeaturesFinder>();
96 #endif // CV_VERSION_MAJOR >= 4
99 const std::vector<cv::Mat>& images,
100 const std::vector<cv::detail::ImageFeatures>& image_features,
101 const std::vector<cv::detail::MatchesInfo>& pairwise_matches)
103 for (
auto& match_info : pairwise_matches) {
104 if (match_info.H.empty() ||
105 match_info.src_img_idx >= match_info.dst_img_idx) {
108 std::cout << match_info.src_img_idx <<
" " << match_info.dst_img_idx
111 << image_features[size_t(match_info.src_img_idx)].keypoints.size()
113 << image_features[size_t(match_info.dst_img_idx)].keypoints.size()
115 <<
"matches: " << match_info.matches.size() << std::endl
116 <<
"inliers: " << match_info.num_inliers << std::endl
117 <<
"inliers/matches ratio: "
118 << match_info.num_inliers / double(match_info.matches.size())
120 <<
"confidence: " << match_info.confidence << std::endl
121 << match_info.H << std::endl;
124 cv::drawMatches(images[
size_t(match_info.src_img_idx)],
125 image_features[
size_t(match_info.src_img_idx)].keypoints,
126 images[
size_t(match_info.dst_img_idx)],
127 image_features[
size_t(match_info.dst_img_idx)].keypoints,
128 match_info.matches, img);
129 cv::imwrite(std::to_string(match_info.src_img_idx) +
"_" +
130 std::to_string(match_info.dst_img_idx) +
"_matches.png",
134 images[
size_t(match_info.src_img_idx)],
135 image_features[
size_t(match_info.src_img_idx)].keypoints,
136 images[
size_t(match_info.dst_img_idx)],
137 image_features[
size_t(match_info.dst_img_idx)].keypoints,
138 match_info.matches, img, cv::Scalar::all(-1), cv::Scalar::all(-1),
139 *
reinterpret_cast<const std::vector<char>*
>(&match_info.inliers_mask));
140 cv::imwrite(std::to_string(match_info.src_img_idx) +
"_" +
141 std::to_string(match_info.dst_img_idx) +
142 "_matches_inliers.png",
150 #endif // ESTIMATION_INTERNAL_H_