now BA in opencv_stitching uses only geometrically consistent matches
This commit is contained in:
parent
15173fc559
commit
29b917a500
@ -35,7 +35,7 @@ int main(int argc, char* argv[])
|
|||||||
string result_name = "result.png";
|
string result_name = "result.png";
|
||||||
int ba_space = BundleAdjuster::FOCAL_RAY_SPACE;
|
int ba_space = BundleAdjuster::FOCAL_RAY_SPACE;
|
||||||
float ba_thresh = 1.f;
|
float ba_thresh = 1.f;
|
||||||
bool wave_correct = false;
|
bool wave_correct = true;
|
||||||
int warp_type = Warper::SPHERICAL;
|
int warp_type = Warper::SPHERICAL;
|
||||||
bool user_match_conf = false;
|
bool user_match_conf = false;
|
||||||
float match_conf = 0.55f;
|
float match_conf = 0.55f;
|
||||||
|
@ -309,13 +309,12 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find pair-wise motion
|
// Find pair-wise motion
|
||||||
vector<uchar> inlier_mask;
|
matches_info.H = findHomography(src_points, dst_points, matches_info.inliers_mask, CV_RANSAC);
|
||||||
matches_info.H = findHomography(src_points, dst_points, inlier_mask, CV_RANSAC);
|
|
||||||
|
|
||||||
// Find number of inliers
|
// Find number of inliers
|
||||||
matches_info.num_inliers = 0;
|
matches_info.num_inliers = 0;
|
||||||
for (size_t i = 0; i < inlier_mask.size(); ++i)
|
for (size_t i = 0; i < matches_info.inliers_mask.size(); ++i)
|
||||||
if (inlier_mask[i])
|
if (matches_info.inliers_mask[i])
|
||||||
matches_info.num_inliers++;
|
matches_info.num_inliers++;
|
||||||
|
|
||||||
// Check if we should try to refine motion
|
// Check if we should try to refine motion
|
||||||
@ -328,8 +327,9 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features
|
|||||||
int inlier_idx = 0;
|
int inlier_idx = 0;
|
||||||
for (size_t i = 0; i < matches_info.matches.size(); ++i)
|
for (size_t i = 0; i < matches_info.matches.size(); ++i)
|
||||||
{
|
{
|
||||||
if (!inlier_mask[i])
|
if (!matches_info.inliers_mask[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const DMatch& m = matches_info.matches[i];
|
const DMatch& m = matches_info.matches[i];
|
||||||
|
|
||||||
Point2f p = features1.keypoints[m.queryIdx].pt;
|
Point2f p = features1.keypoints[m.queryIdx].pt;
|
||||||
@ -346,13 +346,7 @@ void BestOf2NearestMatcher::match(const Mat &img1, const ImageFeatures &features
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rerun motion estimation on inliers only
|
// Rerun motion estimation on inliers only
|
||||||
matches_info.H = findHomography(src_points, dst_points, inlier_mask, CV_RANSAC);
|
matches_info.H = findHomography(src_points, dst_points, CV_RANSAC);
|
||||||
|
|
||||||
// Find number of inliers
|
|
||||||
matches_info.num_inliers = 0;
|
|
||||||
for (size_t i = 0; i < inlier_mask.size(); ++i)
|
|
||||||
if (inlier_mask[i])
|
|
||||||
matches_info.num_inliers++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -505,7 +499,7 @@ void BundleAdjuster::estimate(const vector<Mat> &images, const vector<ImageFeatu
|
|||||||
|
|
||||||
total_num_matches_ = 0;
|
total_num_matches_ = 0;
|
||||||
for (size_t i = 0; i < edges_.size(); ++i)
|
for (size_t i = 0; i < edges_.size(); ++i)
|
||||||
total_num_matches_ += static_cast<int>(pairwise_matches[edges_[i].first * num_images_ + edges_[i].second].matches.size());
|
total_num_matches_ += static_cast<int>(pairwise_matches[edges_[i].first * num_images_ + edges_[i].second].num_inliers);
|
||||||
|
|
||||||
CvLevMarq solver(num_images_ * 4, total_num_matches_ * 3,
|
CvLevMarq solver(num_images_ * 4, total_num_matches_ * 3,
|
||||||
cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 100, DBL_EPSILON));
|
cvTermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 100, DBL_EPSILON));
|
||||||
@ -599,6 +593,9 @@ void BundleAdjuster::calcError(Mat &err)
|
|||||||
|
|
||||||
for (size_t k = 0; k < matches_info.matches.size(); ++k)
|
for (size_t k = 0; k < matches_info.matches.size(); ++k)
|
||||||
{
|
{
|
||||||
|
if (!matches_info.inliers_mask[k])
|
||||||
|
continue;
|
||||||
|
|
||||||
const DMatch& m = matches_info.matches[k];
|
const DMatch& m = matches_info.matches[k];
|
||||||
|
|
||||||
Point2d kp1 = features1.keypoints[m.queryIdx].pt;
|
Point2d kp1 = features1.keypoints[m.queryIdx].pt;
|
||||||
|
@ -44,6 +44,7 @@ struct MatchesInfo
|
|||||||
|
|
||||||
int src_img_idx, dst_img_idx; // Optional images indices
|
int src_img_idx, dst_img_idx; // Optional images indices
|
||||||
std::vector<cv::DMatch> matches;
|
std::vector<cv::DMatch> matches;
|
||||||
|
std::vector<uchar> inliers_mask;
|
||||||
int num_inliers; // Number of geometrically consistent matches
|
int num_inliers; // Number of geometrically consistent matches
|
||||||
cv::Mat H; // Homography
|
cv::Mat H; // Homography
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user