-
Notifications
You must be signed in to change notification settings - Fork 795
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
Changes from 2 commits
8ca7f1f
f60e9e9
64ff24b
b00046c
b0fb6a3
bd0838c
2cf76da
4572282
71b9004
bf93f17
b3601ef
4fbd98d
8a2ce7e
0ecd8ab
ae69e5f
582afe1
15f8b41
e9738c7
65211f8
2e69d09
2e8bfd6
91e58f5
bce9050
620bcf7
f1ea57a
14f8b8a
285f041
373b109
01515d1
c458294
545dfd0
d9a8111
47f9f30
e3b6c83
a69f9e5
119e43a
01561bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
* | ||
* @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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))); | ||
} | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed size There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure to address this! It will save lots compute There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.