#include "libmv/multiview/fundamental.h"
#include "libmv/multiview/fundamental_kernel.h"
#include "libmv/multiview/robust_fundamental.h"
#include "ui/tvr/features.h"
void ComputeFundamental(Matches &all_matches,
Mat3 *F,
Matches *consistent_matches) {
using namespace libmv;
vector<Mat> x;
vector<int> tracks;
vector<int> images;
images.push_back(0);
images.push_back(1);
PointMatchMatrices(all_matches, images, &tracks, &x);
VLOG(2) << "x1\n" << x[0] << "\nx2\n" << x[1] << "\n";
vector<int> inliers;
FundamentalFromCorrespondences7PointRobust(x[0], x[1], 1, F, &inliers);
VLOG(1) << inliers.size() << " inliers\n";
if (inliers.size() < 8) {
return;
}
for (int j = 0; j < inliers.size(); ++j) {
int k = inliers[j];
for (int i = 0; i < 2; ++i) {
consistent_matches->Insert(images[i], tracks[k],
all_matches.Get(images[i], tracks[k]));
}
}
TwoViewPointMatchMatrices(*consistent_matches, 0, 1, &x);
vector<Mat3> Fs;
fundamental::kernel::NormalizedSevenPointKernel::Solve(x[0], x[1], &Fs);
*F = Fs[0];
NormalizeFundamental(*F, F);
LOG(INFO) << "F:\n" << *F;
}