Пример #1
0
Homography autoHomography(const Image<Color>&I1,const Image<Color>&I2,bool ransac=false) {
    Detector d;
    Array<Feat> feats1=d.run(I1);
    drawFeatures(feats1);
    Array<Feat> feats2=d.run(I2);
    drawFeatures(feats2,IntPoint2(I1.width(),0));
    MatchList matches=loweMatch(feats1,feats2,.5,true);
    cout << matches.size() << " matches" << endl;
    drawMatches(feats1,feats2,matches,IntPoint2(0,0),IntPoint2(I1.width(),0),1.,true);
    click();
    if (ransac) {
        Homography H;
        double outlier_thres;
        double median_res = leastMedianOfSquares<4>(matches.begin(), matches.end(), HomEstimator(feats1,feats2), HomResidual(feats1,feats2),H,&outlier_thres);
        MatchList inliers;
        for (MatchList::const_iterator it=matches.begin(); it!=matches.end(); it++) {
            if ( HomResidual(feats1,feats2)(H,*it) < outlier_thres )
                inliers.push_front(*it);
        }
        cout << inliers.size() << " inliers" << endl;
        matches=inliers;
    }
    return meanHomography(feats1,feats2,matches);
}