示例#1
0
MatchList::const_iterator filterOutBestMatch(const MatchList &input) {
	MatchList::const_iterator result = input.begin();

	if (input.size() > 1)
		warning("Multiple entries found for id %d/%s", (*result)->first, getIdString((*result)->first));

	for (MatchList::const_iterator i = input.begin(); i != input.end(); ++i) {
		// Reduce all entries to one single entry.
		//
		// We use the following rules for this (in this order):
		// - Prefer the entry with the higest size
		// - Prefer the entry, which starts at the smallest offest
		//
		// TODO: These rules might not be safe for all games, but hopefully
		// they will work fine. If there are any problems it should be rather
		// easy to identify them, since we print out a warning for multiple
		// entries found.
		if ((*result)->second.desc.hint.size <= (*i)->second.desc.hint.size) {
			if ((*result)->second.offset >= (*i)->second.offset)
				result = i;
		}
	}

	return result;
}
示例#2
0
Homography meanHomography(const Array<Feat>& feats1,const Array<Feat>& feats2,const MatchList& matches) {
    int nb=int(matches.size());
    Matrix<double> A(2*nb,8);
    Vector<double> B(2*nb);
    A.fill(0);
    int k=0;
    // Completer: remplir A et B pour que H verifie AH=B
    for (MatchList::const_iterator it=matches.begin(); it!=matches.end(); k++,it++) {
        Vec2 m1=feats1[it->first].pos;
        Vec2 m2=feats2[it->second].pos;
        // ...
    }
    Matrix<double> C=pseudoInverse(A);	// Moindres carr�s
    if(norm(C)==0)	// non invertible
        return Homography(0.);
    Vector<double> H=C*B;
    return Homography(H.data());	// Painlesss Vector -> FVector conversion
}
示例#3
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);
}