c++ - Iterate through cv::Points contained in a cv::Mat -
i using opencv template matching find image within image.
specifically matchtemplate()
returns cv::mat
containing similarity map of matches.
is there way sort through cv::point
s contained in cv::mat
besides using minmaxloc()
?
minmaxloc(result, &minval, &maxval, &minloc, &maxloc);
i have tried:
cv::mat_<uchar>::iterator = result.begin<uchar>(); cv::mat_<uchar>::iterator end = result.end<uchar>(); (; != end; ++it) { cv::point test(it.pos()); }
with limited success.
if understand correctly, wish sort pixels match score, , points corresponding these pixels in sorted order. can accomplish reshaping result
single row, , calling cv::sortidx()
indices of pixels in sorted order. then, can use indices offsets beginning of result
position of particular pixel.
update: noticed 1 possible issue in code. looks assume result
contains uchar
data. cv::matchtemplate()
requires 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 = indices.begin(); cv::mat_<int>::const_iterator end = indices.end(); (; != end; ++it) { cv::point pt = (begin + *it).pos(); // pt... }
Comments
Post a Comment