1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16
// Third party copyrights are property of their respective owners.
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
24
// * Redistribution's in binary form must reproduce the above copyright notice,
25
// this list of conditions and the following disclaimer in the documentation
26
// and/or other materials provided with the distribution.
28
// * The name of the copyright holders may not be used to endorse or promote products
29
// derived from this software without specific prior written permission.
31
// This software is provided by the copyright holders and contributors "as is" and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall the Intel Corporation or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
44
#include "precomp.hpp"
49
size_t KeyPoint::hash() const
51
size_t _Val = 2166136261U, scale = 16777619U;
53
u.f = pt.x; _Val = (scale * _Val) ^ u.u;
54
u.f = pt.y; _Val = (scale * _Val) ^ u.u;
55
u.f = size; _Val = (scale * _Val) ^ u.u;
56
u.f = angle; _Val = (scale * _Val) ^ u.u;
57
u.f = response; _Val = (scale * _Val) ^ u.u;
58
_Val = (scale * _Val) ^ ((size_t) octave);
59
_Val = (scale * _Val) ^ ((size_t) class_id);
63
void KeyPoint::convert(const std::vector<KeyPoint>& keypoints, std::vector<Point2f>& points2f,
64
const std::vector<int>& keypointIndexes)
66
if( keypointIndexes.empty() )
68
points2f.resize( keypoints.size() );
69
for( size_t i = 0; i < keypoints.size(); i++ )
70
points2f[i] = keypoints[i].pt;
74
points2f.resize( keypointIndexes.size() );
75
for( size_t i = 0; i < keypointIndexes.size(); i++ )
77
int idx = keypointIndexes[i];
79
points2f[i] = keypoints[idx].pt;
82
CV_Error( CV_StsBadArg, "keypointIndexes has element < 0. TODO: process this case" );
83
//points2f[i] = Point2f(-1, -1);
89
void KeyPoint::convert( const std::vector<Point2f>& points2f, std::vector<KeyPoint>& keypoints,
90
float size, float response, int octave, int class_id )
92
keypoints.resize(points2f.size());
93
for( size_t i = 0; i < points2f.size(); i++ )
94
keypoints[i] = KeyPoint(points2f[i], size, -1, response, octave, class_id);
97
float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 )
99
float a = kp1.size * 0.5f;
100
float b = kp2.size * 0.5f;
106
float c = (float)norm( p1 - p2 );
110
// one circle is completely encovered by the other => no intersection points!
111
if( std::min( a, b ) + c <= std::max( a, b ) )
112
return std::min( a_2, b_2 ) / std::max( a_2, b_2 );
114
if( c < a + b ) // circles intersect
117
float cosAlpha = ( b_2 + c_2 - a_2 ) / ( kp2.size * c );
118
float cosBeta = ( a_2 + c_2 - b_2 ) / ( kp1.size * c );
119
float alpha = acos( cosAlpha );
120
float beta = acos( cosBeta );
121
float sinAlpha = sin(alpha);
122
float sinBeta = sin(beta);
124
float segmentAreaA = a_2 * beta;
125
float segmentAreaB = b_2 * alpha;
127
float triangleAreaA = a_2 * sinBeta * cosBeta;
128
float triangleAreaB = b_2 * sinAlpha * cosAlpha;
130
float intersectionArea = segmentAreaA + segmentAreaB - triangleAreaA - triangleAreaB;
131
float unionArea = (a_2 + b_2) * (float)CV_PI - intersectionArea;
133
ovrl = intersectionArea / unionArea;