estimation_internal.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015-2016, Jiri Horner.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of the Jiri Horner nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  *********************************************************************/
36 
37 #ifndef ESTIMATION_INTERNAL_H_
38 #define ESTIMATION_INTERNAL_H_
39 
41 #include <opencv2/core/utility.hpp>
42 #include <opencv2/imgcodecs.hpp>
43 #include <opencv2/stitching/detail/matchers.hpp>
44 
45 namespace combine_grids
46 {
47 namespace internal
48 {
49 static inline cv::Ptr<cv::detail::FeaturesFinder>
51 {
52  switch (type) {
53  case FeatureType::AKAZE:
54  return cv::makePtr<cv::detail::AKAZEFeaturesFinder>();
55  case FeatureType::ORB:
56  return cv::makePtr<cv::detail::OrbFeaturesFinder>();
57  case FeatureType::SURF:
58  return cv::makePtr<cv::detail::SurfFeaturesFinder>();
59  }
60 }
61 
62 static inline void writeDebugMatchingInfo(
63  const std::vector<cv::Mat>& images,
64  const std::vector<cv::detail::ImageFeatures>& image_features,
65  const std::vector<cv::detail::MatchesInfo>& pairwise_matches)
66 {
67  for (auto& match_info : pairwise_matches) {
68  if (match_info.H.empty() ||
69  match_info.src_img_idx >= match_info.dst_img_idx) {
70  continue;
71  }
72  std::cout << match_info.src_img_idx << " " << match_info.dst_img_idx
73  << std::endl
74  << "features: "
75  << image_features[size_t(match_info.src_img_idx)].keypoints.size()
76  << " "
77  << image_features[size_t(match_info.dst_img_idx)].keypoints.size()
78  << std::endl
79  << "matches: " << match_info.matches.size() << std::endl
80  << "inliers: " << match_info.num_inliers << std::endl
81  << "inliers/matches ratio: "
82  << match_info.num_inliers / double(match_info.matches.size())
83  << std::endl
84  << "confidence: " << match_info.confidence << std::endl
85  << match_info.H << std::endl;
86  cv::Mat img;
87  // draw all matches
88  cv::drawMatches(images[size_t(match_info.src_img_idx)],
89  image_features[size_t(match_info.src_img_idx)].keypoints,
90  images[size_t(match_info.dst_img_idx)],
91  image_features[size_t(match_info.dst_img_idx)].keypoints,
92  match_info.matches, img);
93  cv::imwrite(std::to_string(match_info.src_img_idx) + "_" +
94  std::to_string(match_info.dst_img_idx) + "_matches.png",
95  img);
96  // draw inliers only
97  cv::drawMatches(
98  images[size_t(match_info.src_img_idx)],
99  image_features[size_t(match_info.src_img_idx)].keypoints,
100  images[size_t(match_info.dst_img_idx)],
101  image_features[size_t(match_info.dst_img_idx)].keypoints,
102  match_info.matches, img, cv::Scalar::all(-1), cv::Scalar::all(-1),
103  *reinterpret_cast<const std::vector<char>*>(&match_info.inliers_mask));
104  cv::imwrite(std::to_string(match_info.src_img_idx) + "_" +
105  std::to_string(match_info.dst_img_idx) +
106  "_matches_inliers.png",
107  img);
108  }
109 }
110 
111 } // namespace internal
112 } // namespace combine_grids
113 
114 #endif // ESTIMATION_INTERNAL_H_
static void writeDebugMatchingInfo(const std::vector< cv::Mat > &images, const std::vector< cv::detail::ImageFeatures > &image_features, const std::vector< cv::detail::MatchesInfo > &pairwise_matches)
static cv::Ptr< cv::detail::FeaturesFinder > chooseFeatureFinder(FeatureType type)


map_merge
Author(s): Jiri Horner
autogenerated on Mon Jun 10 2019 13:56:52