Regarding cvFeatureTree Function

View: New views
1 Messages — Rating Filter:   Alert me  

Regarding cvFeatureTree Function

by Chen Kai-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi:
    Recently I am doing object recognition using SURF implemented in OpenCV 1.1pre version, after cvExtractSURF function, I tried cvFeatureTree and cvFindFeatures functions to find correspond points between two images. And whether a descriptor is matched is decided by comparing two nearest descriptors, if distMin1 < 0.6 * distMin2, then it's accepted. But it was strange when using cvFindFeatures, it cannot find any correspond points meeting above criteria. Meanwhile, a most naive function to find matched points will work.(Test data is the same)
    So I am writing to ask if there is anything wrong with this function, or I just misused it.
 
    Part of the source code :
 
CvMemStorage* storage = cvCreateMemStorage(0);
 
//Load image from disk
IplImage* IplGray1,* IplGray2;
IplGray1 = cvLoadImage(argv[2], CV_LOAD_IMAGE_GRAYSCALE );
IplGray2 = cvLoadImage(argv[2], CV_LOAD_IMAGE_GRAYSCALE );
 
CvSURFParams surfParam = cvSURFParams(1000.0, 1);
CvSeq* img1KPoints,* img2KPoints;
CvSeq* img1Descriptors,* img2Descriptors;
 
cvExtractSURF(IplGray1, 0, &img1KPoints, &img1Descriptors, storage, surfParam);
cvExtractSURF(IplGray2, 0, &img2KPoints, &img2Descriptors, storage, surfParam);
 
//two image's descriptor numbers.
int img1DescNum = img1Descriptors->total;
int img2DescNum = img2Descriptors->total;
int length = img1Descriptors->elem_size / sizeof(float);//Descriptor length
 
CvMat* desc1Mat,* desc2Mat;
desc1Mat = cvCreateMat(img1DescNum, length, CV_32FC1);
desc2Mat = cvCreateMat(img2DescNum, length, CV_32FC1);
 
//copy descriptor sequence to matrix
for (int i(0); i < img1DescNum; i++)
{
     float* curDesc = (float*)cvGetSeqElem(img1Descriptors, i);
     for (int k(0); k < length; k++)
          CV_MAT_ELEM(*desc1Mat, float, i, k) = curDesc[k];
}
for (int i(0); i < img2DescNum; i++)
{
     float* curDesc = (float*)cvGetSeqElem(img2Descriptors, i);
     for (int k(0); k < length; k++)
          CV_MAT_ELEM(*desc2Mat, float, i, k) = curDesc[k];
}
 
//Uses KD-Tree in OpenCV to match key points:
CvFeatureTree* KDTree = cvCreateFeatureTree(desc1Mat);
CvMat* matResults,* matDist;
matResults = cvCreateMat(img2DescNum, 2, CV_32S);
matDist = cvCreateMat(img2DescNum, 2, CV_64FC1);
cvFindFeatures(KDTree, desc2Mat, matResults, matDist, 2, 400);//To find 2 nearest neighbors
int numMatched(0);
for (int i(0); i < matDist->rows; i++)
{
    double dist1 = CV_MAT_ELEM(*matDist, double, i, 0);
    double dist2 = CV_MAT_ELEM(*matDist, double, i, 1);
    double minDist = MIN(dist1, dist2);
    double maxDist = MAX(dist2, dist2);
    if (minDist < 0.6 * maxDist)// Check if it meets the criteria
    {
        int idx1, idx2;
        idx1 = CV_MAT_ELEM(*matResults, int, i, 0);
        idx2 = CV_MAT_ELEM(*matResults, int, i, 1);
        CvSURFPoint* pt1,* pt2;
        pt1 = (CvSURFPoint*)cvGetSeqElem(img1KPoints, idx1);
        pt2 = (CvSURFPoint*)cvGetSeqElem(img2KPoints, idx2);
 
        //This line is for visualizing
        //cvLine(IplMatched, cvPoint(pt1->pt.x, pt2->pt.y), cvPoint(pt2->pt.x + IplImg1->width, pt2->pt.y), colors[i%8]);
  
        numMatched++;
    }
}
printf("%d points matched using KD-tree-BBF search!\n", numMatched);
//Result: numMatched is always 0 or 1...
//Where did I go wrong?
 
    Thank you for your time.
    Looking forward to your reply.
 
-------------------------------
Best Wishes

School of Computer Science and Technology
University of Science and Technology of China

K.Chen

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel