コード例 #1
0
void Reconstruction::ReconstructPlanarUnconstrIter(const mat& matchesInit, LaplacianMesh& resMesh, uvec& inlierMatchIdxs)
{
  // Input check
  if (matchesInit.n_rows == 0) 
  {
    inlierMatchIdxs.resize(0);
    return;
  }

  Timer timer;

  double wr     = this->wrInit;      // Currently used regularization weight 
  double radius = this->radiusInit;  // Currently used radius of the estimator
  vec    reprojErrors;               // Reprojection errors

  // First, we need to build the correspondent matrix with all given matches to avoid re-computation
  this->buildCorrespondenceMatrix(matchesInit);

  // Then compute MPinit. Function reconstructPlanarUnconstr() will use part of MPinit w.r.t currently used matches
  this->MPinit = this->Minit * this->refMesh.GetBigParamMat();

  uvec matchesInitIdxs = linspace<uvec>(0, matchesInit.n_rows-1, matchesInit.n_rows);

  // Currently used matches represented by their indices. Initially, use all matches: [0,1,2..n-1]
  inlierMatchIdxs = matchesInitIdxs;
  
  for (int i = 0; i < nUncstrIters; i++)
  {
    this->reconstructPlanarUnconstr(inlierMatchIdxs, wr, resMesh);
    
    // If it is the final iteration, break and don't update "inlierMatchIdxs" or "weights", "radius"
    if (i == nUncstrIters - 1) 
    {
      //cout << "Current radius: " << radius << endl;
      //cout << "Current wr: " << wr << endl;
      //Reconstruction::computeCurrentMatrices(currentMatchIdxs, 325);  // For Ferns
      break;
    }

    // Otherwise, remove outliers
    int iterTO = nUncstrIters - 2;
    if (i >= iterTO)
      reprojErrors = this->computeReprojectionErrors(resMesh, matchesInit, matchesInitIdxs);
    else
      reprojErrors = this->computeReprojectionErrors(resMesh, matchesInit, inlierMatchIdxs);

    uvec idxs = find( reprojErrors < radius );
    if (idxs.n_elem == 0)
      break;

    if (i >= iterTO)
      inlierMatchIdxs = matchesInitIdxs.elem(idxs);
    else
      inlierMatchIdxs = inlierMatchIdxs.elem(idxs);

    // Update parameters
    wr     = wr     / Reconstruction::ROBUST_SCALE;
    radius = radius / Reconstruction::ROBUST_SCALE;
  }
}