Skip to content

Commit 39e7427

Browse files
vipinanand4alalek
authored andcommitted
Merge pull request opencv#9618 from vipinanand4:goodFeaturesToTrack_added_gradiantSize
Added gradiantSize param into goodFeaturesToTrack API (opencv#9618) * Added gradiantSize param into goodFeaturesToTrack API Removed hardcode value 3 in goodFeaturesToTrack API, and added new param 'gradinatSize' in this API so that user can pass any gradiant size as 3, 5 or 7. Signed-off-by: Vipin Anand <anand.vipin@gmail.com> Signed-off-by: Nilaykumar Patel<nilay.nilpat@gmail.com> Signed-off-by: Prashanth Voora <prashanthx85@gmail.com> * fixed compilation error for java test Signed-off-by: Vipin Anand <anand.vipin@gmail.com> * Modifying code for previous binary compatibility and fixing other warnings fixed ABI break issue resolved merged conflict compilation error fix Signed-off-by: Vipin Anand <anand.vipin@gmail.com> Signed-off-by: Patel, Nilaykumar K <nilay.nilpat@gmail.com>
1 parent 50aa4f8 commit 39e7427

File tree

12 files changed

+65
-27
lines changed

12 files changed

+65
-27
lines changed

modules/features2d/include/opencv2/features2d.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ class CV_EXPORTS_W GFTTDetector : public Feature2D
527527
public:
528528
CV_WRAP static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
529529
int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
530+
CV_WRAP static Ptr<GFTTDetector> create( int maxCorners, double qualityLevel, double minDistance,
531+
int blockSize, int gradiantSize, bool useHarrisDetector=false, double k=0.04 );
530532
CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
531533
CV_WRAP virtual int getMaxFeatures() const = 0;
532534

modules/features2d/src/gftt.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class GFTTDetector_Impl : public GFTTDetector
4848
{
4949
public:
5050
GFTTDetector_Impl( int _nfeatures, double _qualityLevel,
51-
double _minDistance, int _blockSize,
51+
double _minDistance, int _blockSize, int _gradientSize,
5252
bool _useHarrisDetector, double _k )
5353
: nfeatures(_nfeatures), qualityLevel(_qualityLevel), minDistance(_minDistance),
54-
blockSize(_blockSize), useHarrisDetector(_useHarrisDetector), k(_k)
54+
blockSize(_blockSize), gradSize(_gradientSize), useHarrisDetector(_useHarrisDetector), k(_k)
5555
{
5656
}
5757

@@ -67,6 +67,9 @@ class GFTTDetector_Impl : public GFTTDetector
6767
void setBlockSize(int blockSize_) { blockSize = blockSize_; }
6868
int getBlockSize() const { return blockSize; }
6969

70+
void setGradientSize(int gradientSize_) { gradSize = gradientSize_; }
71+
int getGradientSize() { return gradSize; }
72+
7073
void setHarrisDetector(bool val) { useHarrisDetector = val; }
7174
bool getHarrisDetector() const { return useHarrisDetector; }
7275

@@ -88,7 +91,7 @@ class GFTTDetector_Impl : public GFTTDetector
8891
ugrayImage = _image.getUMat();
8992

9093
goodFeaturesToTrack( ugrayImage, corners, nfeatures, qualityLevel, minDistance, _mask,
91-
blockSize, useHarrisDetector, k );
94+
blockSize, gradSize, useHarrisDetector, k );
9295
}
9396
else
9497
{
@@ -97,7 +100,7 @@ class GFTTDetector_Impl : public GFTTDetector
97100
cvtColor( image, grayImage, COLOR_BGR2GRAY );
98101

99102
goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, _mask,
100-
blockSize, useHarrisDetector, k );
103+
blockSize, gradSize, useHarrisDetector, k );
101104
}
102105

103106
keypoints.resize(corners.size());
@@ -112,17 +115,26 @@ class GFTTDetector_Impl : public GFTTDetector
112115
double qualityLevel;
113116
double minDistance;
114117
int blockSize;
118+
int gradSize;
115119
bool useHarrisDetector;
116120
double k;
117121
};
118122

119123

124+
Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel,
125+
double _minDistance, int _blockSize, int _gradientSize,
126+
bool _useHarrisDetector, double _k )
127+
{
128+
return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel,
129+
_minDistance, _blockSize, _gradientSize, _useHarrisDetector, _k);
130+
}
131+
120132
Ptr<GFTTDetector> GFTTDetector::create( int _nfeatures, double _qualityLevel,
121133
double _minDistance, int _blockSize,
122134
bool _useHarrisDetector, double _k )
123135
{
124136
return makePtr<GFTTDetector_Impl>(_nfeatures, _qualityLevel,
125-
_minDistance, _blockSize, _useHarrisDetector, _k);
137+
_minDistance, _blockSize, 3, _useHarrisDetector, _k);
126138
}
127139

128140
String GFTTDetector::getDefaultName() const

modules/features2d/test/test_keypoints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ TEST(Features2d_Detector_Keypoints_AGAST, validation)
139139
TEST(Features2d_Detector_Keypoints_HARRIS, validation)
140140
{
141141

142-
CV_FeatureDetectorKeypointsTest test(GFTTDetector::create(1000, 0.01, 1, 3, true, 0.04));
142+
CV_FeatureDetectorKeypointsTest test(GFTTDetector::create(1000, 0.01, 1, 3, 3, true, 0.04));
143143
test.safe_run();
144144
}
145145

modules/imgproc/include/opencv2/imgproc.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,11 +1914,17 @@ or cornerMinEigenVal.
19141914
19151915
@sa cornerMinEigenVal, cornerHarris, calcOpticalFlowPyrLK, estimateRigidTransform,
19161916
*/
1917+
19171918
CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
19181919
int maxCorners, double qualityLevel, double minDistance,
19191920
InputArray mask = noArray(), int blockSize = 3,
19201921
bool useHarrisDetector = false, double k = 0.04 );
19211922

1923+
CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
1924+
int maxCorners, double qualityLevel, double minDistance,
1925+
InputArray mask, int blockSize,
1926+
int gradientSize, bool useHarrisDetector = false,
1927+
double k = 0.04 );
19221928
/** @example houghlines.cpp
19231929
An example using the Hough line detector
19241930
![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg)

modules/imgproc/misc/java/test/ImgprocTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDou
10331033
Imgproc.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1);
10341034
MatOfPoint lp = new MatOfPoint();
10351035

1036-
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, true, 0);
1036+
Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, 3, true, 0);
10371037

10381038
assertEquals(4, lp.total());
10391039
}

modules/imgproc/perf/opencl/perf_gftt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ OCL_PERF_TEST_P(GoodFeaturesToTrackFixture, GoodFeaturesToTrack,
7777
declare.in(src, WARMUP_READ).out(dst);
7878

7979
OCL_TEST_CYCLE() cv::goodFeaturesToTrack(src, dst, maxCorners, qualityLevel,
80-
minDistance, noArray(), 3, harrisDetector, 0.04);
80+
minDistance, noArray(), 3, 3, harrisDetector, 0.04);
8181

8282
SANITY_CHECK(dst);
8383
}

modules/imgproc/perf/perf_goodFeaturesToTrack.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ using namespace perf;
66
using std::tr1::make_tuple;
77
using std::tr1::get;
88

9-
typedef std::tr1::tuple<string, int, double, int, bool> Image_MaxCorners_QualityLevel_MinDistance_BlockSize_UseHarris_t;
10-
typedef perf::TestBaseWithParam<Image_MaxCorners_QualityLevel_MinDistance_BlockSize_UseHarris_t> Image_MaxCorners_QualityLevel_MinDistance_BlockSize_UseHarris;
9+
typedef std::tr1::tuple<string, int, double, int, int, bool> Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris_t;
10+
typedef perf::TestBaseWithParam<Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris_t> Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris;
1111

12-
PERF_TEST_P(Image_MaxCorners_QualityLevel_MinDistance_BlockSize_UseHarris, goodFeaturesToTrack,
12+
PERF_TEST_P(Image_MaxCorners_QualityLevel_MinDistance_BlockSize_gradientSize_UseHarris, goodFeaturesToTrack,
1313
testing::Combine(
1414
testing::Values( "stitching/a1.png", "cv/shared/pic5.png"),
1515
testing::Values( 100, 500 ),
1616
testing::Values( 0.1, 0.01 ),
1717
testing::Values( 3, 5 ),
18+
testing::Values( 3, 5 ),
1819
testing::Bool()
1920
)
2021
)
@@ -23,7 +24,8 @@ PERF_TEST_P(Image_MaxCorners_QualityLevel_MinDistance_BlockSize_UseHarris, goodF
2324
int maxCorners = get<1>(GetParam());
2425
double qualityLevel = get<2>(GetParam());
2526
int blockSize = get<3>(GetParam());
26-
bool useHarrisDetector = get<4>(GetParam());
27+
int gradientSize = get<4>(GetParam());
28+
bool useHarrisDetector = get<5>(GetParam());
2729

2830
Mat image = imread(filename, IMREAD_GRAYSCALE);
2931
if (image.empty())
@@ -32,7 +34,7 @@ PERF_TEST_P(Image_MaxCorners_QualityLevel_MinDistance_BlockSize_UseHarris, goodF
3234
std::vector<Point2f> corners;
3335

3436
double minDistance = 1;
35-
TEST_CYCLE() goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance, noArray(), blockSize, useHarrisDetector);
37+
TEST_CYCLE() goodFeaturesToTrack(image, corners, maxCorners, qualityLevel, minDistance, noArray(), blockSize, gradientSize, useHarrisDetector);
3638

3739
if (corners.size() > 50)
3840
corners.erase(corners.begin() + 50, corners.end());

modules/imgproc/src/featureselect.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ struct Corner
7575

7676
static bool ocl_goodFeaturesToTrack( InputArray _image, OutputArray _corners,
7777
int maxCorners, double qualityLevel, double minDistance,
78-
InputArray _mask, int blockSize,
78+
InputArray _mask, int blockSize, int gradientSize,
7979
bool useHarrisDetector, double harrisK )
8080
{
8181
UMat eig, maxEigenValue;
8282
if( useHarrisDetector )
83-
cornerHarris( _image, eig, blockSize, 3, harrisK );
83+
cornerHarris( _image, eig, blockSize, gradientSize, harrisK );
8484
else
85-
cornerMinEigenVal( _image, eig, blockSize, 3 );
85+
cornerMinEigenVal( _image, eig, blockSize, gradientSize );
8686

8787
Size imgsize = _image.size();
8888
size_t total, i, j, ncorners = 0, possibleCornersCount =
@@ -275,7 +275,7 @@ struct VxKeypointsComparator
275275

276276
static bool openvx_harris(Mat image, OutputArray _corners,
277277
int _maxCorners, double _qualityLevel, double _minDistance,
278-
int _blockSize, double _harrisK)
278+
int _blockSize, int gradiantSize, double _harrisK)
279279
{
280280
using namespace ivx;
281281

@@ -357,7 +357,7 @@ static bool openvx_harris(Mat image, OutputArray _corners,
357357

358358
void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
359359
int maxCorners, double qualityLevel, double minDistance,
360-
InputArray _mask, int blockSize,
360+
InputArray _mask, int blockSize, int gradientSize,
361361
bool useHarrisDetector, double harrisK )
362362
{
363363
CV_INSTRUMENT_REGION()
@@ -367,7 +367,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
367367

368368
CV_OCL_RUN(_image.dims() <= 2 && _image.isUMat(),
369369
ocl_goodFeaturesToTrack(_image, _corners, maxCorners, qualityLevel, minDistance,
370-
_mask, blockSize, useHarrisDetector, harrisK))
370+
_mask, blockSize, gradientSize, useHarrisDetector, harrisK))
371371

372372
Mat image = _image.getMat(), eig, tmp;
373373
if (image.empty())
@@ -379,12 +379,12 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
379379
// Disabled due to bad accuracy
380380
CV_OVX_RUN(false && useHarrisDetector && _mask.empty() &&
381381
!ovx::skipSmallImages<VX_KERNEL_HARRIS_CORNERS>(image.cols, image.rows),
382-
openvx_harris(image, _corners, maxCorners, qualityLevel, minDistance, blockSize, harrisK))
382+
openvx_harris(image, _corners, maxCorners, qualityLevel, minDistance, blockSize, gradiantSize, harrisK))
383383

384384
if( useHarrisDetector )
385-
cornerHarris( image, eig, blockSize, 3, harrisK );
385+
cornerHarris( image, eig, blockSize, gradientSize, harrisK );
386386
else
387-
cornerMinEigenVal( image, eig, blockSize, 3 );
387+
cornerMinEigenVal( image, eig, blockSize, gradientSize );
388388

389389
double maxVal = 0;
390390
minMaxLoc( eig, 0, &maxVal, 0, 0, _mask );
@@ -535,4 +535,12 @@ cvGoodFeaturesToTrack( const void* _image, void*, void*,
535535
*_corner_count = (int)ncorners;
536536
}
537537

538+
void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners,
539+
int maxCorners, double qualityLevel, double minDistance,
540+
InputArray _mask, int blockSize,
541+
bool useHarrisDetector, double harrisK )
542+
{
543+
cv::goodFeaturesToTrack(_image, _corners, maxCorners, qualityLevel, minDistance,
544+
_mask, blockSize, 3, useHarrisDetector, harrisK );
545+
}
538546
/* End of file. */

modules/imgproc/test/test_goodfeaturetotrack.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test_cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size,
161161
static void
162162
test_goodFeaturesToTrack( InputArray _image, OutputArray _corners,
163163
int maxCorners, double qualityLevel, double minDistance,
164-
InputArray _mask, int blockSize,
164+
InputArray _mask, int blockSize, int gradientSize,
165165
bool useHarrisDetector, double harrisK )
166166
{
167167

@@ -170,7 +170,7 @@ test_goodFeaturesToTrack( InputArray _image, OutputArray _corners,
170170

171171

172172
Mat image = _image.getMat(), mask = _mask.getMat();
173-
int aperture_size = 3;
173+
int aperture_size = gradientSize;
174174
int borderType = BORDER_DEFAULT;
175175

176176
Mat eig, tmp, tt;
@@ -330,6 +330,7 @@ class CV_GoodFeatureToTTest : public cvtest::ArrayTest
330330
double qualityLevel;
331331
double minDistance;
332332
int blockSize;
333+
int gradientSize;
333334
bool useHarrisDetector;
334335
double k;
335336
int SrcType;
@@ -343,6 +344,7 @@ CV_GoodFeatureToTTest::CV_GoodFeatureToTTest()
343344
qualityLevel = 0.01;
344345
minDistance = 10;
345346
blockSize = 3;
347+
gradientSize = 3;
346348
useHarrisDetector = false;
347349
k = 0.04;
348350
mask = Mat();
@@ -397,6 +399,7 @@ void CV_GoodFeatureToTTest::run_func()
397399
minDistance,
398400
Mat(),
399401
blockSize,
402+
gradientSize,
400403
useHarrisDetector,
401404
k );
402405
}
@@ -414,6 +417,7 @@ void CV_GoodFeatureToTTest::run_func()
414417
minDistance,
415418
Mat(),
416419
blockSize,
420+
gradientSize,
417421
useHarrisDetector,
418422
k );
419423
}
@@ -438,6 +442,7 @@ int CV_GoodFeatureToTTest::validate_test_results( int test_case_idx )
438442
minDistance,
439443
Mat(),
440444
blockSize,
445+
gradientSize,
441446
useHarrisDetector,
442447
k );
443448
}
@@ -455,6 +460,7 @@ int CV_GoodFeatureToTTest::validate_test_results( int test_case_idx )
455460
minDistance,
456461
Mat(),
457462
blockSize,
463+
gradientSize,
458464
useHarrisDetector,
459465
k );
460466
}

samples/cpp/lkdemo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ int main( int argc, char** argv )
8181
if( needToInit )
8282
{
8383
// automatic initialization
84-
goodFeaturesToTrack(gray, points[1], MAX_COUNT, 0.01, 10, Mat(), 3, 0, 0.04);
84+
goodFeaturesToTrack(gray, points[1], MAX_COUNT, 0.01, 10, Mat(), 3, 3, 0, 0.04);
8585
cornerSubPix(gray, points[1], subPixWinSize, Size(-1,-1), termcrit);
8686
addRemovePt = false;
8787
}

0 commit comments

Comments
 (0)