| 67 | } |
| 68 | |
| 69 | double TemplateComparator::comp(const cv::Mat& lhs, const cv::Mat& rhs, int method) |
| 70 | { |
| 71 | bool invert_score = false; |
| 72 | if (method >= TemplateMatcherParam::kMethodInvertBase) { |
| 73 | invert_score = true; |
| 74 | method -= TemplateMatcherParam::kMethodInvertBase; |
| 75 | } |
| 76 | |
| 77 | cv::Mat matched; |
| 78 | cv::matchTemplate(lhs, rhs, matched, method); |
| 79 | |
| 80 | if (invert_score) { |
| 81 | matched = 1.0f - matched; |
| 82 | } |
| 83 | |
| 84 | double min_val = 0.0, max_val = 0.0; |
| 85 | cv::Point min_loc { }, max_loc { }; |
| 86 | cv::minMaxLoc(matched, &min_val, &max_val, &min_loc, &max_loc); |
| 87 | |
| 88 | double val = low_score_better_ ? min_val : max_val; |
| 89 | |
| 90 | if (std::isnan(val) || std::isinf(val)) { |
| 91 | val = low_score_better_ ? std::numeric_limits<double>::max() : 0; |
| 92 | } |
| 93 | |
| 94 | return val; |
| 95 | } |
| 96 | |
| 97 | bool TemplateComparator::comp_score(double s1, double s2) const |
| 98 | { |
nothing calls this directly
no outgoing calls
no test coverage detected