| 98 | } |
| 99 | |
| 100 | int CountPatternMatches(const cv::Mat &result, const cv::Size &patternSize) |
| 101 | { |
| 102 | if (result.empty()) { |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | cv::Mat work = result.clone(); |
| 107 | int count = 0; |
| 108 | |
| 109 | while (true) { |
| 110 | double maxVal; |
| 111 | cv::Point maxLoc; |
| 112 | cv::minMaxLoc(work, nullptr, &maxVal, nullptr, &maxLoc); |
| 113 | if (maxVal <= 0.0) { |
| 114 | break; |
| 115 | } |
| 116 | count++; |
| 117 | // Suppress the template-sized region around this match so |
| 118 | // overlapping high-scoring positions are not counted separately |
| 119 | int x = std::max(0, maxLoc.x - patternSize.width / 2); |
| 120 | int y = std::max(0, maxLoc.y - patternSize.height / 2); |
| 121 | int w = std::min(patternSize.width, work.cols - x); |
| 122 | int h = std::min(patternSize.height, work.rows - y); |
| 123 | work(cv::Rect(x, y, w, h)) = 0.0f; |
| 124 | } |
| 125 | |
| 126 | return count; |
| 127 | } |
| 128 | |
| 129 | double MatchPattern(QImage &img, QImage &pattern, double threshold, |
| 130 | cv::Mat &result, bool useAlphaAsMask, |
no test coverage detected