stereo keypt

1.

vector gkeyPoint1;
vector gkeyPoint2;  
std::vector< DMatch > good_matches;

Point gaPointDisplay[5000];

 

2.      SurfFeatureDetector surfDetector(20);  //hessianThreshold,海塞矩阵阈值,并不是限定特征点的个数    
       

        surfDetector.detect(rectifyImageL,gkeyPoint1);
        surfDetector.detect(rectifyImageR,gkeyPoint2);  

        SurfDescriptorExtractor extractor;
        Mat descriptors1, descriptors2;
        extractor.compute(rectifyImageL, gkeyPoint1, descriptors1);
        extractor.compute(rectifyImageR, gkeyPoint2, descriptors2);

        BruteForceMatcher< L2 > matcher;
        //std::vector< DMatch > matches;
        //匹配两幅图中的描述子(descriptors)
        matcher.match(descriptors1, descriptors2, matches);

        //过滤匹配点
        double max_dist = 0; double min_dist = 100;
        //-- Quick calculation of max and min distances between keypoints
        for( int i = 0; i < descriptors1.rows; i++ )
        { 
            double dist = matches[i].distance;
            if( dist < min_dist ) min_dist = dist;
            if( dist > max_dist ) max_dist = dist;
        }


        printf("-- Max dist : %f \n", max_dist );
        printf("-- Min dist : %f \n", min_dist );

        int igoodNum = 0;
        //-- Draw only "good" matches (i.e. whose distance is less than 0.6*max_dist )
        //-- PS.- radiusMatch can also be used here.
        //std::vector< DMatch > good_matches;
        for( int i = 0; i < descriptors1.rows; i++ )
        { 
            //if( matches[i].distance < 0.6*max_dist )
            if( matches[i].distance < 0.3*max_dist )
            { 
                good_matches.push_back( matches[i]); 

                if(igoodNum > 4500) {
                    printf("igoodNum:%d two many good num point.\n",igoodNum);
                    break;
                }

                gaPointDisplay[igoodNum] = gkeyPoint1[matches[i].queryIdx].pt;
                igoodNum ++;

                int queryIdx = matches[i].queryIdx;
                int trainIdx =  matches[i].trainIdx;

                cv::Point2f  pt1 = gkeyPoint1[queryIdx].pt;
                cv::Point2f  pt2 = gkeyPoint2[trainIdx].pt;

                circle(rectifyImageL,pt1,2,Scalar(255,0,0,0),CV_FILLED,CV_AA,0);//划圆  
                circle(rectifyImageR,pt2,2,Scalar(255,0,0,0),CV_FILLED,CV_AA,0);//划圆  
            }
        }
 

 

 

你可能感兴趣的:(stereo keypt)