Structure From two views
Features
this project is modified from Chapter4_StructureFromMotion
non gpu version is better for beginner of learning CV . i.e. compile the project would be easy .
structure from two views
non opencv3_contrib verison
Fix bug in the project
original in Distance.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| void OnlyMatchFeatures(int strategy = STRATEGY_USE_OPTICAL_FLOW + STRATEGY_USE_DENSE_OF + STRATEGY_USE_FEATURE_MATCH) { imgpts1.clear(); imgpts2.clear(); fullpts1.clear(); fullpts2.clear(); std::vector<cv::Mat> imgs; imgs.push_back(left_im); imgs.push_back(right_im); std::vector<std::vector<cv::KeyPoint> > imgpts; imgpts.push_back(imgpts1); imgpts.push_back(imgpts2); RichFeatureMatcher rfm(imgs,imgpts); rfm.MatchFeatures(0, 1); imgpts1 = rfm.GetImagePoints(0); imgpts2 = rfm.GetImagePoints(1); features_matched = true; }
void RecoverDepthFromImages() { if(!features_matched) OnlyMatchFeatures(); std::vector<cv::DMatch> matches; FindCameraMatrices(K, Kinv, distortion_coeff, imgpts1, imgpts2, imgpts1_good, imgpts2_good, P, P1, matches, pointcloud
|
modified in Distance.h
- the variable matches is set as global in class Distance
- rfm.MatchFeatures(0, 1,&matches);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| void OnlyMatchFeatures(int strategy = STRATEGY_USE_OPTICAL_FLOW + STRATEGY_USE_DENSE_OF + STRATEGY_USE_FEATURE_MATCH) { imgpts1.clear(); imgpts2.clear(); fullpts1.clear(); fullpts2.clear(); std::vector<cv::Mat> imgs; imgs.push_back(left_im); imgs.push_back(right_im); std::vector<std::vector<cv::KeyPoint> > imgpts; imgpts.push_back(imgpts1); imgpts.push_back(imgpts2); RichFeatureMatcher rfm(imgs,imgpts);
rfm.MatchFeatures(0, 1,&matches); imgpts1 = rfm.GetImagePoints(0); imgpts2 = rfm.GetImagePoints(1); features_matched = true; }
|
Reasons
- function MatchFeatures() will update variable matches
- the correct algorithm order is function FindCameraMatrices() after get matches
- if the variable matches is empty ,there is no necessary to compute camera matrix
Parse SFM project
Files Function
UML
process diagram
Project repository
original–Chapter4_StructureFromMotion
this project