Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding factor which considers the essential matrix and camera calibration as variable #753

Merged
merged 37 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8ca7f1f
Adding factor with shared calibration as a variable
ayushbaid Apr 23, 2021
f60e9e9
fixing tests by moving to Cal3_S2
ayushbaid Apr 24, 2021
64ff24b
using fixed size matrix, and adding jacobian in homogeneous conversion
ayushbaid Apr 27, 2021
b00046c
Merge branch 'develop' into feature/essential-mat-with-approx-k
ayushbaid Apr 27, 2021
b0fb6a3
renaming key variable
ayushbaid Apr 27, 2021
bd0838c
fixing docstring
ayushbaid Apr 27, 2021
2cf76da
reverting jacobian computation from homogeneous function
ayushbaid Apr 27, 2021
4572282
adding prior on calibrations
ayushbaid Apr 28, 2021
71b9004
Merge branch 'develop' into feature/essential-mat-with-approx-k
ayushbaid May 25, 2021
bf93f17
Merge branch 'develop' of github.com:borglab/gtsam into feature/essen…
akshay-krishnan Jun 8, 2021
b3601ef
updating tests
ayushbaid Jun 8, 2021
4fbd98d
creating 18 point example
ayushbaid Jun 8, 2021
8a2ce7e
switching to sampson point line error
ayushbaid Jun 9, 2021
0ecd8ab
fixing jacobians and reformatting
ayushbaid Jun 9, 2021
ae69e5f
changing error values in test
ayushbaid Jun 9, 2021
582afe1
Merge branch 'feature/sampson-epipolar-error' into feature/essential-…
ayushbaid Jun 9, 2021
15f8b41
adding jacobians on input points
ayushbaid Jun 9, 2021
e9738c7
adding jacobians on input points
ayushbaid Jun 9, 2021
65211f8
moving to squared sampson error
ayushbaid Jun 9, 2021
2e69d09
Merge branch 'feature/sampson-epipolar-error' into feature/essential-…
ayushbaid Jun 9, 2021
2e8bfd6
using correct jacobian computation for calibration
ayushbaid Jun 10, 2021
91e58f5
fixing unit tests
ayushbaid Jun 10, 2021
bce9050
adding 11 point example for cal3bundler
ayushbaid Jun 10, 2021
620bcf7
fixing test cases
ayushbaid Jun 10, 2021
f1ea57a
Merge branch 'feature/essential-mat-with-approx-k' of github.com:borg…
akshay-krishnan Jun 12, 2021
14f8b8a
removing Sampson error + some tests cleanup
akshay-krishnan Jun 14, 2021
285f041
increasing calibrate() tolerance
akshay-krishnan Jun 14, 2021
373b109
small covariance change
akshay-krishnan Jun 14, 2021
01515d1
formatting changes
akshay-krishnan Jun 14, 2021
c458294
removing duplicate data file
akshay-krishnan Jun 14, 2021
545dfd0
removing failing test and unused data
akshay-krishnan Jun 17, 2021
d9a8111
resolving merge conflict
akshay-krishnan Jun 17, 2021
47f9f30
updating documentation for factor
akshay-krishnan Jun 17, 2021
e3b6c83
updating points name, constexpr
akshay-krishnan Jun 21, 2021
a69f9e5
changing to macro EssenstialMatrixfactor4
akshay-krishnan Jun 21, 2021
119e43a
all jacobian tests for essential matrix use macro
akshay-krishnan Jun 21, 2021
01561bc
formatting example
akshay-krishnan Jun 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions gtsam/slam/EssentialMatrixWithCalibrationFactor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* ----------------------------------------------------------------------------

* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)

* See LICENSE for the license information

* -------------------------------------------------------------------------- */

/**
* @file EssentialMatrixWithCalibrationFactor.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be in it’s on file, or can you just be added to the other factor file. You could call it essential matrix factory 3 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am calling it EssentialMatrixFactor4 as we have 3 factors already.

*
* @brief A factor evaluating algebraic epipolar error with essential matrix and
* calibration as variables.
*
* @author Ayush Baid
* @author Akshay Krishnan
* @date April 23, 2021
*/

#pragma once

#include <gtsam/geometry/EssentialMatrix.h>
#include <gtsam/nonlinear/NonlinearFactor.h>

#include <iostream>

namespace gtsam {

/**
* Factor that evaluates algebraic epipolar error (K^-1 p)'E (K^-1 p) for given
* essential matrix and calibration shared between two images.
*/
template <class CALIBRATION>
class EssentialMatrixWithCalibrationFactor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a simpler name here? Not sure that it conveys the overall gist of the factor.

EssentialMatrixProjectionFactor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is a bit tricky as we are not doing any reprojection to compute error, which is what this name suggests to me.

The word projection does not hint that calibration is a parameter.

: public NoiseModelFactor2<EssentialMatrix, CALIBRATION> {
Point2 pA_, pB_; ///< points in pixel coordinates
ayushbaid marked this conversation as resolved.
Show resolved Hide resolved

typedef NoiseModelFactor2<EssentialMatrix, CALIBRATION> Base;
typedef EssentialMatrixWithCalibrationFactor This;

public:
/**
* Constructor
* @param essentialMatrixKey Essential Matrix variable key
* @param calibrationKey Calibration variable key
* @param pA point in first camera, in pixel coordinates
* @param pB point in second camera, in pixel coordinates
* @param model noise model is about dot product in ideal, homogeneous
* coordinates
*/
EssentialMatrixWithCalibrationFactor(Key essentialMatrixKey,
Key calibrationKey, const Point2& pA,
const Point2& pB,
const SharedNoiseModel& model)
: Base(model, essentialMatrixKey, calibrationKey), pA_(pA), pB_(pB) {}

/// @return a deep copy of this factor
gtsam::NonlinearFactor::shared_ptr clone() const override {
return boost::static_pointer_cast<gtsam::NonlinearFactor>(
gtsam::NonlinearFactor::shared_ptr(new This(*this)));
}

/// print
void print(
const std::string& s = "",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override {
Base::print(s);
std::cout << " EssentialMatrixWithCalibrationFactor with measurements\n ("
<< pA_.transpose() << ")' and (" << pB_.transpose() << ")'"
<< std::endl;
}

/// vector of errors returns 1D vector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add this to the documentation below?

/**
* @brief Calculate the algebraic epipolar error p' (K^-1)' E K p.
*
* @param E essential matrix for key essentialMatrixKey
* @param K calibration (common for both images) for key calibrationKey
* @param H1 optional jacobian in E
ayushbaid marked this conversation as resolved.
Show resolved Hide resolved
* @param H2 optional jacobian in K
* @return * Vector
*/
Vector evaluateError(
const EssentialMatrix& E, const CALIBRATION& K,
boost::optional<Matrix&> H1 = boost::none,
boost::optional<Matrix&> H2 = boost::none) const override {
Vector error(1);
// converting from pixel coordinates to normalized coordinates cA and cB
Matrix cA_H_K; // dcA/dK
Matrix cB_H_K; // dcB/dK
Point2 cA = K.calibrate(pA_, cA_H_K);
ayushbaid marked this conversation as resolved.
Show resolved Hide resolved
Point2 cB = K.calibrate(pB_, cB_H_K);

// Homogeneous the coordinates
Vector3 vA = EssentialMatrix::Homogeneous(cA);
Vector3 vB = EssentialMatrix::Homogeneous(cB);

if (H2) {
// compute the jacobian of error w.r.t K

// dvX / dcX [3x2] = [1, 0], [0, 1], [0, 0]
ayushbaid marked this conversation as resolved.
Show resolved Hide resolved
Matrix v_H_c =
(Matrix(3, 2) << 1.0, 0.0, 0.0, 1.0, 0.0, 0.0).finished(); // [3x2]
ayushbaid marked this conversation as resolved.
Show resolved Hide resolved

// computing dvA/dK = dvA/dcA * dcA/dK and dVB/dK = dvB/dcB * dcB/dK
Matrix vA_H_K = v_H_c * cA_H_K;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed size

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, take a look at v_h_C and what this means for this product :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to address this! It will save lots compute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added fixed size variable. The product looks right to me. Is it wrong?

Matrix vB_H_K = v_H_c * cB_H_K;

// error function f = vB.T * E * vA
// H2 = df/dK = vB.T * E.T * dvA/dK + vA.T * E * dvB/dK
*H2 = vB.transpose() * E.matrix().transpose() * vA_H_K +
vA.transpose() * E.matrix() * vB_H_K;
akshay-krishnan marked this conversation as resolved.
Show resolved Hide resolved
}

error << E.error(vA, vB, H1);
dellaert marked this conversation as resolved.
Show resolved Hide resolved

return error;
}

public:
GTSAM_MAKE_ALIGNED_OPERATOR_NEW
};

} // namespace gtsam
Loading