0

I use the following function to create a GFTT keypoint detector:

 poKpDetector1 = FeatureDetector::create( "GFTT" );

Then call the following function to adjust desired values for it's input parameters:

    void FuncSet_GFTT_InpParams( Ptr<FeatureDetector>& poKpDetector1 )
    {
        poKpDetector1->set( "nfeatures"         , MyInpParamsStruct.nKpDet_GFTT1_MaxCornerNo );
        poKpDetector1->set( "qualityLevel"      , MyInpParamsStruct.dKpDet_GFTT1_QualityLevel );
        poKpDetector1->set( "minDistance"       , MyInpParamsStruct.dKpDet_GFTT1_MinDistance );
        poKpDetector1->set( "useHarrisDetector" , MyInpParamsStruct.bKpDet_GFTT1_UseHarrisDetector );
        poKpDetector1->set( "k"                 , MyInpParamsStruct.dKpDet_GFTT1_HarrisDetectorK );
    }

Looking in features2d_init.cpp I was unable to find how can I use "set" function (having a pointer to FeatureDetector type) to adjust "blockSize" parameter for GFTT.

The following two tries fails:

 poKpDetector1->set( "blocksize", MyInpParamsStruct.nKpDet_GFTT1_BlockSize );

or

 (*((cv::GFTTDetector*)((poKpDetector1).obj))).blockSize = MyInpParamsStruct.nKpDet_GFTT1_BlockSize;

Is there a way to adjust blocksize parameter of GFTT using only the pointer returned by FeatureDetector::create function? Thank you in advance for any help.

Yashil
  • 170
  • 1
  • 2
  • 13

2 Answers2

0

You use blocksize (all lower case) but the Parameter is named blockSize (camelCase).

Try:

poKpDetector1->set( "blockSize", MyInpParamsStruct.nKpDet_GFTT1_BlockSize );

EDIT: If you don´t mind a few lines of more code you could use this:

Mat grayImage = image;
if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY );

vector<Point2f> corners;
goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, mask,
                     blockSize, useHarrisDetector, k );
keypoints.resize(corners.size());
vector<Point2f>::const_iterator corner_it = corners.begin();
vector<KeyPoint>::iterator keypoint_it = keypoints.begin();
for( ; corner_it != corners.end(); ++corner_it, ++keypoint_it )
{
    *keypoint_it = KeyPoint( *corner_it, (float)blockSize );
}

which is the implementation of the GFTT Wrapper. Here you can simply change the blockSize according to your needs. The default Values are:

int maxCorners=1000
double qualityLevel=0.01,
double minDistance=1.
int blockSize=3,
bool useHarrisDetector=false
double k=0.04

EDIT2:
You can also try out the Code from this Answer. It prints out all Parameters off a Feature detector. After Printing out the Parameter name you should see the something like "blockSize". You can than use this name to set the Parameter using the code from my original Answer.

Community
  • 1
  • 1
Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46
  • It does not work either, @Mailerdaimon. I have tried several other forms for blockSize name and they all crash with "Unhandled exception" at calling time of "->set" function. I was unable to find a proper string name for this parameter in features2d_init.cpp – Yashil Nov 26 '13 at 05:50
  • @Yashil hmm.. This is the way it should work. However I have given you to other possible solutions (see edited Answer). Please report back if one of them works for you. – Mailerdaimon Nov 26 '13 at 07:29
  • Tx for your follow-up. I know using goodFeaturesToTrack I will be able to adjust blockSize parameter value for GFTT feature. But as I said in the question I am trying to do that using only the pointer returned by FeatureDetector::create function. I also tried algorithm->getParams function from your link, but it only returns 5 params that I used in my FuncSet_GFTT_InpParams function and does not include blockSize (Only returns the ones that defined in OpenCVs features2d_init.cpp ). – Yashil Nov 26 '13 at 11:55
  • Based on what I see for HARRIS in features2d_init.cpp will not work for HARRIS either. CV_INIT_ALGORITHM(HarrisDetector, "Feature2D.HARRIS", obj.info()->addParam(obj, "nfeatures", obj.nfeatures); obj.info()->addParam(obj, "qualityLevel", obj.qualityLevel); obj.info()->addParam(obj, "minDistance", obj.minDistance); obj.info()->addParam(obj, "useHarrisDetector", obj.useHarrisDetector); obj.info()->addParam(obj, "k", obj.k)); – Yashil Nov 26 '13 at 12:55
0

Don't know if this helps but you also can create a FeatureDetector-Pointer with:

cv::Ptr<cv::FeatureDetector> poKpDtector = new cv::GoodFeaturesToTrackDetector(maxCorners,qualityLevel,minDistance,blockSize,useHarrisDetector,k);

There you can specify e.g. blockSize as well.

It still has the same downside that you can't change this parameter at runtime...

Michael
  • 115
  • 1
  • 10