Skip to content

Commit 2cf76da

Browse files
committed
reverting jacobian computation from homogeneous function
1 parent bd0838c commit 2cf76da

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

gtsam/geometry/EssentialMatrix.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
#pragma once
99

10-
#include <gtsam/base/Manifold.h>
11-
#include <gtsam/geometry/Point2.h>
1210
#include <gtsam/geometry/Pose3.h>
1311
#include <gtsam/geometry/Unit3.h>
12+
#include <gtsam/geometry/Point2.h>
13+
#include <gtsam/base/Manifold.h>
1414

1515
#include <iosfwd>
1616
#include <string>
@@ -31,11 +31,7 @@ class EssentialMatrix {
3131

3232
public:
3333
/// Static function to convert Point2 to homogeneous coordinates
34-
static Vector3 Homogeneous(const Point2& p,
35-
OptionalJacobian<3, 2> H = boost::none) {
36-
if (H) {
37-
H->setIdentity();
38-
}
34+
static Vector3 Homogeneous(const Point2& p) {
3935
return Vector3(p.x(), p.y(), 1);
4036
}
4137

gtsam/geometry/tests/testEssentialMatrix.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,6 @@ TEST (EssentialMatrix, epipoles) {
241241
EXPECT(assert_equal(e2, E.epipole_b()));
242242
}
243243

244-
//*************************************************************************
245-
TEST(EssentialMatrix, Homogeneous) {
246-
Point2 input(5.0, 1.3);
247-
Vector3 expected(5.0, 1.3, 1.0);
248-
Matrix32 expectedH;
249-
expectedH << 1.0, 0.0, 0.0, 1.0, 0.0, 0.0;
250-
Matrix32 actualH;
251-
Vector3 actual = EssentialMatrix::Homogeneous(input, actualH);
252-
EXPECT(assert_equal(actual, expected));
253-
EXPECT(assert_equal(actualH, expectedH));
254-
}
255-
256244
/* ************************************************************************* */
257245
int main() {
258246
TestResult tr;

gtsam/slam/EssentialMatrixFactor.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,28 +354,28 @@ class EssentialMatrixFactor4
354354
const EssentialMatrix& E, const CALIBRATION& K,
355355
boost::optional<Matrix&> H1 = boost::none,
356356
boost::optional<Matrix&> H2 = boost::none) const override {
357-
Vector error(1);
358357
// converting from pixel coordinates to normalized coordinates cA and cB
359358
JacobianCalibration cA_H_K; // dcA/dK
360359
JacobianCalibration cB_H_K; // dcB/dK
361360
Point2 cA = K.calibrate(pA_, H2 ? &cA_H_K : 0);
362361
Point2 cB = K.calibrate(pB_, H2 ? &cB_H_K : 0);
363362

364-
// Homogeneous the coordinates
365-
Matrix32 vA_H_cA, vB_H_cB;
366-
Vector3 vA = EssentialMatrix::Homogeneous(cA, H2 ? &vA_H_cA : 0);
367-
Vector3 vB = EssentialMatrix::Homogeneous(cB, H2 ? &vB_H_cB : 0);
363+
// convert to homogeneous coordinates
364+
Vector3 vA = EssentialMatrix::Homogeneous(cA);
365+
Vector3 vB = EssentialMatrix::Homogeneous(cB);
368366

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

372370
// error function f = vA.T * E * vB
373371
// H2 = df/dK = vB.T * E.T * dvA/dK + vA.T * E * dvB/dK
374372
// where dvA/dK = dvA/dcA * dcA/dK, dVB/dK = dvB/dcB * dcB/dK
375-
*H2 = vB.transpose() * E.matrix().transpose() * vA_H_cA * cA_H_K +
376-
vA.transpose() * E.matrix() * vB_H_cB * cB_H_K;
373+
// and dvA/dcA = dvB/dcB = [[1, 0], [0, 1], [0, 0]]
374+
*H2 = vB.transpose() * E.matrix().transpose().leftCols<2>() * cA_H_K +
375+
vA.transpose() * E.matrix().leftCols<2>() * cB_H_K;
377376
}
378377

378+
Vector error(1);
379379
error << E.error(vA, vB, H1);
380380

381381
return error;

0 commit comments

Comments
 (0)