If you understand correctly, you want to sort the pixels by their coincidence, and then get the points corresponding to these pixels in sorted order. You can do this by changing the result one line, and then call cv::sortIdx() to get the pixel indices in sorted cv::sortIdx() you can use the indices as offsets from the beginning of the result to get the position of that particular pixel.
UPDATE: I noticed one possible problem in your code. It looks like you think that result contains uchar data. cv::matchTemplate() requires that result contain float data.
cv::Mat_<int> indices; cv::sortIdx(result.reshape(0,1), indices, CV_SORT_DESCENDING + CV_SORT_EVERY_ROW); cv::Mat_<float>::const_iterator begin = result.begin<float>(); cv::Mat_<int>::const_iterator it = indices.begin(); cv::Mat_<int>::const_iterator end = indices.end(); for (; it != end; ++it) { cv::Point pt = (begin + *it).pos(); // Do something with pt... }
source share