Structure From two views

Structure From two views

Features

  1. this project is modified from Chapter4_StructureFromMotion

  2. non gpu version is better for beginner of learning CV . i.e. compile the project would be easy .

  3. structure from two views

  4. 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

  1. the variable matches is set as global in class Distance
  2. 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) {//Q
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); //detect feature & compute descriptors as globle of class RichFeatureMatcher


//pans0ul fix
rfm.MatchFeatures(0, 1,&matches);

imgpts1 = rfm.GetImagePoints(0); //imgpts1 is globle of Distance
imgpts2 = rfm.GetImagePoints(1);

features_matched = true;
}

Reasons

  1. function MatchFeatures() will update variable matches
  2. the correct algorithm order is function FindCameraMatrices() after get matches
  3. 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


Structure From two views
https://pans0ul.github.io/2020/04/28/StructureFrom2views/
Author
pans0ul
Posted on
April 28, 2020
Licensed under