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 : public GFTTDetector 48 { 49 public: 50 GFTTDetector_Impl( int _nfeatures, double _qualityLevel, 51 double _minDistance, int _blockSize, 52 bool _useHarrisDetector, double _k ) 53 : nfeatures(_nfeatures), qualityLevel(_qualityLevel), minDistance(_minDistance), 54 blockSize(_blockSize), useHarrisDetector(_useHarrisDetector), k(_k) 55 { 56 } 57 58 void setMaxFeatures(int maxFeatures) { nfeatures = maxFeatures; } 59 int getMaxFeatures() const { return nfeatures; } 60 61 void setQualityLevel(double qlevel) { qualityLevel = qlevel; } 62 double getQualityLevel() const { return qualityLevel; } 63 64 void setMinDistance(double minDistance_) { minDistance = minDistance_; } 65 double getMinDistance() const { return minDistance; } 66 67 void setBlockSize(int blockSize_) { blockSize = blockSize_; } 68 int getBlockSize() const { return blockSize; } 69 70 void setHarrisDetector(bool val) { useHarrisDetector = val; } 71 bool getHarrisDetector() const { return useHarrisDetector; } 72 73 void setK(double k_) { k = k_; } 74 double getK() const { return k; } 75 76 void detect( InputArray _image, std::vector<KeyPoint>& keypoints, InputArray _mask ) 77 { 78 std::vector<Point2f> corners; 79 80 if (_image.isUMat()) 81 { 82 UMat ugrayImage; 83 if( _image.type() != CV_8U ) 84 cvtColor( _image, ugrayImage, COLOR_BGR2GRAY ); 85 else 86 ugrayImage = _image.getUMat(); 87 88 goodFeaturesToTrack( ugrayImage, corners, nfeatures, qualityLevel, minDistance, _mask, 89 blockSize, useHarrisDetector, k ); 90 } 91 else 92 { 93 Mat image = _image.getMat(), grayImage = image; 94 if( image.type() != CV_8U ) 95 cvtColor( image, grayImage, COLOR_BGR2GRAY ); 96 97 goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, _mask, 98 blockSize, useHarrisDetector, k ); 99 } 100 101 keypoints.resize(corners.size()); 102 std::vector<Point2f>::const_iterator corner_it = corners.begin(); 103 std::vector<KeyPoint>::iterator keypoint_it = keypoints.begin(); 104 for( ; corner_it != corners.end(); ++corner_it, ++keypoint_it ) 105 *keypoint_it = KeyPoint( *corner_it, (float)blockSize ); 106 107 } 108 109 int nfeatures; 110 double qualityLevel; 111 double minDistance; 112 int blockSize; 113 bool useHarrisDetector; 114 double k; 115 }; 116 117 118 Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel, 119 double _minDistance, int _blockSize, 120 bool _useHarrisDetector, double _k ) 121 { 122 return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel, 123 _minDistance, _blockSize, _useHarrisDetector, _k); 124 } 125 126 } 127