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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
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.
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.
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.
42 #include "precomp.hpp"
47 class GFTTDetector_Impl CV_FINAL : public GFTTDetector
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)
58 void setMaxFeatures(int maxFeatures) CV_OVERRIDE { nfeatures = maxFeatures; }
59 int getMaxFeatures() const CV_OVERRIDE { return nfeatures; }
61 void setQualityLevel(double qlevel) CV_OVERRIDE { qualityLevel = qlevel; }
62 double getQualityLevel() const CV_OVERRIDE { return qualityLevel; }
64 void setMinDistance(double minDistance_) CV_OVERRIDE { minDistance = minDistance_; }
65 double getMinDistance() const CV_OVERRIDE { return minDistance; }
67 void setBlockSize(int blockSize_) CV_OVERRIDE { blockSize = blockSize_; }
68 int getBlockSize() const CV_OVERRIDE { return blockSize; }
70 //void setGradientSize(int gradientSize_) { gradSize = gradientSize_; }
71 //int getGradientSize() { return gradSize; }
73 void setHarrisDetector(bool val) CV_OVERRIDE { useHarrisDetector = val; }
74 bool getHarrisDetector() const CV_OVERRIDE { return useHarrisDetector; }
76 void setK(double k_) CV_OVERRIDE { k = k_; }
77 double getK() const CV_OVERRIDE { return k; }
79 void detect( InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask ) CV_OVERRIDE
81 CV_INSTRUMENT_REGION();
89 std::vector<Point2f> corners;
90 std::vector<float> cornersQuality;
95 if( _image.type() != CV_8U )
96 cvtColor( _image, ugrayImage, COLOR_BGR2GRAY );
98 ugrayImage = _image.getUMat();
100 goodFeaturesToTrack( ugrayImage, corners, nfeatures, qualityLevel, minDistance, _mask,
101 cornersQuality, blockSize, gradSize, useHarrisDetector, k );
105 Mat image = _image.getMat(), grayImage = image;
106 if( image.type() != CV_8U )
107 cvtColor( image, grayImage, COLOR_BGR2GRAY );
109 goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, _mask,
110 cornersQuality, blockSize, gradSize, useHarrisDetector, k );
113 CV_Assert(corners.size() == cornersQuality.size());
115 keypoints.resize(corners.size());
116 for (size_t i = 0; i < corners.size(); i++)
117 keypoints[i] = KeyPoint(corners[i], (float)blockSize, -1, cornersQuality[i]);
126 bool useHarrisDetector;
131 Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel,
132 double _minDistance, int _blockSize, int _gradientSize,
133 bool _useHarrisDetector, double _k )
135 return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel,
136 _minDistance, _blockSize, _gradientSize, _useHarrisDetector, _k);
139 Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel,
140 double _minDistance, int _blockSize,
141 bool _useHarrisDetector, double _k )
143 return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel,
144 _minDistance, _blockSize, 3, _useHarrisDetector, _k);
147 String GFTTDetector::getDefaultName() const
149 return (Feature2D::getDefaultName() + ".GFTTDetector");