Skip to content

Commit

Permalink
Merge pull request #368 from oddkiva/maint-code-cleanup
Browse files Browse the repository at this point in the history
MAINT: code cleanup.
  • Loading branch information
oddkiva authored Jan 5, 2024
2 parents 95afb11 + f94b105 commit a04e475
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 83 deletions.
57 changes: 0 additions & 57 deletions python/oddkiva/combination.py

This file was deleted.

2 changes: 2 additions & 0 deletions python/oddkiva/sara/sfm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The code in this folder are mostly a collection of results we reuse in the C++
code.
33 changes: 20 additions & 13 deletions python/oddkiva/sara/sfm/five_point_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import sympy as sp
from sympy.abc import x, y, z
def calculate_E_matrix_constraints_from_5_point():
import sympy as sp
from sympy.abc import x, y, z

# Solve the cubic polynomial.
X = sp.MatrixSymbol('X', 3, 3)
Y = sp.MatrixSymbol('Y', 3, 3)
Z = sp.MatrixSymbol('Z', 3, 3)
W = sp.MatrixSymbol('W', 3, 3)
# Solve the cubic polynomial.
#
# The essential matrix lives in the nullspace which is spanned by 4
# eigenvectors.
X = sp.MatrixSymbol('X', 3, 3)
Y = sp.MatrixSymbol('Y', 3, 3)
Z = sp.MatrixSymbol('Z', 3, 3)
W = sp.MatrixSymbol('W', 3, 3)

# Form the symbolic matrix expression as reported in the paper.
E = sp.Matrix(x * X + y * Y + z * Z + W)
# Form the symbolic matrix expression as reported in the paper.
E = sp.Matrix(x * X + y * Y + z * Z + W)

essential_constraint = E * E.T * E - sp.Trace(E * E.T) * E
rank_2_constraint = E.det()
# Form the first system of equations that the essential matrix must
# satisfy:
essential_constraint = E * E.T * E - sp.Trace(E * E.T) * E

e = essential_constraint
# Form the second system of equations. The essential matrix has rank 2,
# therefore its determinant must be zero.
rank_2_constraint = E.det()

import IPython; IPython.embed()
return essential_constraint, rank_2_constraint
29 changes: 16 additions & 13 deletions python/oddkiva/sara/sfm/seven_point_algorithm.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import sympy as sp
def calculate_F_matrix_rank_2_constraint_from_7_points():
import sympy as sp

# Solve the cubic polynomial.
F1 = sp.MatrixSymbol('F1', 3, 3)
F2 = sp.MatrixSymbol('F2', 3, 3)
α = sp.symbols('α')
# Solve the cubic polynomial.
F1 = sp.MatrixSymbol('F1', 3, 3)
F2 = sp.MatrixSymbol('F2', 3, 3)
α = sp.symbols('α')

# Form the symbolic matrix expression as reported in the paper.
F = sp.Matrix(F1 + α * F2)
# The fundamental matrix has rank 2.
# Necessarily its determinant must be 0.
#
# Form the symbolic matrix expression as reported in the paper.
F = sp.Matrix(F1 + α * F2)

# Form the polynomial in the variable α.
det_F, _ = sp.polys.poly_from_expr(F.det(), α)
# Form the polynomial in the variable α.
det_F, _ = sp.polys.poly_from_expr(F.det(), α)

# Collect the coefficients "c[i]" as denoted in the paper.
c = det_F.all_coeffs()
# Collect the coefficients "c[i]" as denoted in the paper.
c = det_F.all_coeffs()


import IPython; IPython.embed()
return c

0 comments on commit a04e475

Please sign in to comment.