Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/features2d/src/gftt.cpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
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.
8
//
9
//
10
// Intel License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000, Intel Corporation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
15
//
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
18
//
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
21
//
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
25
//
26
// * The name of Intel Corporation may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
28
//
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
39
//
40
//M*/
41
42
#include "precomp.hpp"
43
44
namespace cv
45
{
46
47
class GFTTDetector_Impl CV_FINAL : public GFTTDetector
48
{
49
public:
50
GFTTDetector_Impl( int _nfeatures, double _qualityLevel,
51
double _minDistance, int _blockSize, int _gradientSize,
52
bool _useHarrisDetector, double _k )
53
: nfeatures(_nfeatures), qualityLevel(_qualityLevel), minDistance(_minDistance),
54
blockSize(_blockSize), gradSize(_gradientSize), useHarrisDetector(_useHarrisDetector), k(_k)
55
{
56
}
57
58
void setMaxFeatures(int maxFeatures) CV_OVERRIDE { nfeatures = maxFeatures; }
59
int getMaxFeatures() const CV_OVERRIDE { return nfeatures; }
60
61
void setQualityLevel(double qlevel) CV_OVERRIDE { qualityLevel = qlevel; }
62
double getQualityLevel() const CV_OVERRIDE { return qualityLevel; }
63
64
void setMinDistance(double minDistance_) CV_OVERRIDE { minDistance = minDistance_; }
65
double getMinDistance() const CV_OVERRIDE { return minDistance; }
66
67
void setBlockSize(int blockSize_) CV_OVERRIDE { blockSize = blockSize_; }
68
int getBlockSize() const CV_OVERRIDE { return blockSize; }
69
70
//void setGradientSize(int gradientSize_) { gradSize = gradientSize_; }
71
//int getGradientSize() { return gradSize; }
72
73
void setHarrisDetector(bool val) CV_OVERRIDE { useHarrisDetector = val; }
74
bool getHarrisDetector() const CV_OVERRIDE { return useHarrisDetector; }
75
76
void setK(double k_) CV_OVERRIDE { k = k_; }
77
double getK() const CV_OVERRIDE { return k; }
78
79
void detect( InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask ) CV_OVERRIDE
80
{
81
CV_INSTRUMENT_REGION();
82
83
if(_image.empty())
84
{
85
keypoints.clear();
86
return;
87
}
88
89
std::vector<Point2f> corners;
90
91
if (_image.isUMat())
92
{
93
UMat ugrayImage;
94
if( _image.type() != CV_8U )
95
cvtColor( _image, ugrayImage, COLOR_BGR2GRAY );
96
else
97
ugrayImage = _image.getUMat();
98
99
goodFeaturesToTrack( ugrayImage, corners, nfeatures, qualityLevel, minDistance, _mask,
100
blockSize, gradSize, useHarrisDetector, k );
101
}
102
else
103
{
104
Mat image = _image.getMat(), grayImage = image;
105
if( image.type() != CV_8U )
106
cvtColor( image, grayImage, COLOR_BGR2GRAY );
107
108
goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, _mask,
109
blockSize, gradSize, useHarrisDetector, k );
110
}
111
112
keypoints.resize(corners.size());
113
std::vector<Point2f>::const_iterator corner_it = corners.begin();
114
std::vector<KeyPoint>::iterator keypoint_it = keypoints.begin();
115
for( ; corner_it != corners.end() && keypoint_it != keypoints.end(); ++corner_it, ++keypoint_it )
116
*keypoint_it = KeyPoint( *corner_it, (float)blockSize );
117
118
}
119
120
int nfeatures;
121
double qualityLevel;
122
double minDistance;
123
int blockSize;
124
int gradSize;
125
bool useHarrisDetector;
126
double k;
127
};
128
129
130
Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel,
131
double _minDistance, int _blockSize, int _gradientSize,
132
bool _useHarrisDetector, double _k )
133
{
134
return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel,
135
_minDistance, _blockSize, _gradientSize, _useHarrisDetector, _k);
136
}
137
138
Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel,
139
double _minDistance, int _blockSize,
140
bool _useHarrisDetector, double _k )
141
{
142
return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel,
143
_minDistance, _blockSize, 3, _useHarrisDetector, _k);
144
}
145
146
String GFTTDetector::getDefaultName() const
147
{
148
return (Feature2D::getDefaultName() + ".GFTTDetector");
149
}
150
151
}
152
153