From af2af3af9bf7735b8f4a08bf29e74c56d8623284 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 31 May 2011 14:24:45 +0000 Subject: [PATCH] added KeyPoint::hash() (ticket #1100) --- .../include/opencv2/features2d/features2d.hpp | 5 ++++- modules/features2d/src/keypoint.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 3f339f135..98beda2b0 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -236,6 +236,9 @@ public: float _response=0, int _octave=0, int _class_id=-1) : pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {} + + size_t hash() const; + //! converts vector of keypoints to vector of points static void convert(const std::vector& keypoints, CV_OUT std::vector& points2f, @@ -257,7 +260,7 @@ public: CV_PROP_RW int octave; //!< octave (pyramid layer) from which the keypoint has been extracted CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to) }; - + //! writes vector of keypoints to the file storage CV_EXPORTS void write(FileStorage& fs, const string& name, const vector& keypoints); //! reads vector of keypoints from the specified file storage node diff --git a/modules/features2d/src/keypoint.cpp b/modules/features2d/src/keypoint.cpp index 6f76026a5..21ebce277 100644 --- a/modules/features2d/src/keypoint.cpp +++ b/modules/features2d/src/keypoint.cpp @@ -43,7 +43,20 @@ namespace cv { - + +size_t KeyPoint::hash() const +{ + size_t _Val = 2166136261U, scale = 16777619U; + Cv32suf u; + u.f = pt.x; _Val = (scale * _Val) ^ u.u; + u.f = pt.y; _Val = (scale * _Val) ^ u.u; + u.f = size; _Val = (scale * _Val) ^ u.u; + u.f = angle; _Val = (scale * _Val) ^ u.u; + u.f = response; _Val = (scale * _Val) ^ u.u; + _Val = (scale * _Val) ^ ((size_t) octave); + _Val = (scale * _Val) ^ ((size_t) class_id); + return _Val; +} void write(FileStorage& fs, const string& objname, const vector& keypoints) {