c++ - std::map with cv::Point as key -
c++ - std::map with cv::Point as key -
i need create std::map<cv::point, double>
. cv::point
type of point opencv library. has fields like: x
, y
.
cv::point
not have <
operator of course. have thought how define have optimal access element in std::map
?
in other words. have illustration 20000 points. need quite fast access every point.
for example:
std::map<cv::point, double> mymap; point p(10, 234); int value = 777; mymap[p] = value; // need operation quite fast decided utilize std::map
but cv::point not have <
operator. can prepare <
operator (it comparing illustration x coordinate):
bool operator<(const cv::point a, const cv::point b) { homecoming a.x < a.x; }
but guess not operator. many points has same value of x.
how prepare efficient operator in case?
according this documentation, cv::point
represents 2 dimensional datapoint. this, can define operator <
via standard lexicographic ordering:
bool operator<(cv::point const& a, cv::point const& b) { homecoming (a.x < b.x) || (a.x == b.x && a.y < b.y); }
edit: considered using unordered_map
: although might more appropriate here, bit more complicated implement have combine 2 hash-values of x
, y
. can utilize boost::hash_combine
or figure out reasonable on own, see becomes more complicated.
c++ algorithm opencv data-structures stl
Comments
Post a Comment