This source file includes following definitions.
- hash
- convert
- convert
- overlap
#include "precomp.hpp"
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 KeyPoint::convert(const std::vector<KeyPoint>& keypoints, std::vector<Point2f>& points2f,
const std::vector<int>& keypointIndexes)
{
if( keypointIndexes.empty() )
{
points2f.resize( keypoints.size() );
for( size_t i = 0; i < keypoints.size(); i++ )
points2f[i] = keypoints[i].pt;
}
else
{
points2f.resize( keypointIndexes.size() );
for( size_t i = 0; i < keypointIndexes.size(); i++ )
{
int idx = keypointIndexes[i];
if( idx >= 0 )
points2f[i] = keypoints[idx].pt;
else
{
CV_Error( CV_StsBadArg, "keypointIndexes has element < 0. TODO: process this case" );
}
}
}
}
void KeyPoint::convert( const std::vector<Point2f>& points2f, std::vector<KeyPoint>& keypoints,
float size, float response, int octave, int class_id )
{
keypoints.resize(points2f.size());
for( size_t i = 0; i < points2f.size(); i++ )
keypoints[i] = KeyPoint(points2f[i], size, -1, response, octave, class_id);
}
float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 )
{
float a = kp1.size * 0.5f;
float b = kp2.size * 0.5f;
float a_2 = a * a;
float b_2 = b * b;
Point2f p1 = kp1.pt;
Point2f p2 = kp2.pt;
float c = (float)norm( p1 - p2 );
float ovrl = 0.f;
if( std::min( a, b ) + c <= std::max( a, b ) )
return std::min( a_2, b_2 ) / std::max( a_2, b_2 );
if( c < a + b )
{
float c_2 = c * c;
float cosAlpha = ( b_2 + c_2 - a_2 ) / ( kp2.size * c );
float cosBeta = ( a_2 + c_2 - b_2 ) / ( kp1.size * c );
float alpha = acos( cosAlpha );
float beta = acos( cosBeta );
float sinAlpha = sin(alpha);
float sinBeta = sin(beta);
float segmentAreaA = a_2 * beta;
float segmentAreaB = b_2 * alpha;
float triangleAreaA = a_2 * sinBeta * cosBeta;
float triangleAreaB = b_2 * sinAlpha * cosAlpha;
float intersectionArea = segmentAreaA + segmentAreaB - triangleAreaA - triangleAreaB;
float unionArea = (a_2 + b_2) * (float)CV_PI - intersectionArea;
ovrl = intersectionArea / unionArea;
}
return ovrl;
}
}