miop.factorization

Classes

Factorization(reproErrorTh, normalized_view)

Builds a measurement matrix from corresponding points and factorizes it to recover the movement of the cameras.

class miop.factorization.Factorization(reproErrorTh, normalized_view, max_matches=0, batch_size=4)[source]

Bases: DAGNode

Builds a measurement matrix from corresponding points and factorizes it to recover the movement of the cameras.

reproErrorTh

Threshold for the reprojection error.

Type:

float

max_matches

Maximum number of matches to consider (default is 0, meaning no limit).

Type:

int

batch_size

Number of images to process in each batch (default is 4).

Type:

int

rot_angles

List of rotation angles for the camera movements. Set in eval().

Type:

list

build_measurement_matrix(matches)[source]

Constructs a measurement matrix from corresponding points in multiple images.

Parameters:

matches (numpy.ndarray) – Array of shape (m, n, 2), where m is number of images, n is number of points, and 2 corresponds to (x, y) coordinates.

Returns:

meas_matnumpy.ndarray

The constructed measurement matrix of shape (2*m, n).

centersnumpy.ndarray

The centroids of the matches used for centering the points, shape (m, 2).

Return type:

tuple

compute_rmse(distances)[source]

Computes the root mean square error (RMSE) from a list of distances.

Parameters:

distances (array-like) – List or array of distance errors.

Returns:

The computed RMSE value.

Return type:

float

eval(matches)[source]

Computes camera parameters from corresponding matches using factorization on batches of images.

The camera movements for each batch are propagated to the rest of the face. The first camera of each face is used as relative origin with zero tilt. The tilt angles are forced positive, so the image collection should have monotonically increasing tilt angles.

Parameters:

matches (list of list of numpy.ndarray) – Corresponding points across the image collection. The first list level represents faces.

Returns:

A list containing the computed camera parameters for each face.

Return type:

list

factorization_sc(W, decomp='eigen', normRot=0)[source]

Performs factorization using the scaling and camera motion model described by Poelman and Kanade.

Parameters:
  • W (numpy.ndarray) – The measurement matrix containing point correspondences across frames.

  • decomp (str, optional) – Decomposition method to use: ‘eigen’ or ‘cholesky’ (default is ‘eigen’).

  • normRot (int, optional) – Index of the camera used as reference for normalization (default is 0).

Returns:

RotationMatriceslist of numpy.ndarray

List of rotation matrices for each frame.

Shapenumpy.ndarray

The estimated 3D shape matrix.

kiNewlist

Normalized scaling factors for each frame.

paramsnumpy.ndarray

Additional parameters (2-element array).

Qnumpy.ndarray

The matrix used for correction.

kilist

Original scaling factors for each frame.

Return type:

tuple

factorize(measurementMatrix, centroids)[source]

Factorizes the measurement matrix to estimate camera rotations and intrinsics.

Parameters:
  • measurementMatrix (numpy.ndarray) – The measurement matrix to factorize.

  • centroids (numpy.ndarray) – Centroids of matched points for adjustment during factorization.

Returns:

Dictionary containing: - ‘rotations’: numpy.ndarray of estimated rotation matrix. - ‘intrinsics’: list containing normalized scaling factors and parameters.

Return type:

dict

gT(a, b)[source]

Computes the constraint vector used in the metric upgrade process.

Parameters:
  • a (np.ndarray) – An array of shape (frames, 3) representing camera motion vectors.

  • b (np.ndarray) – An array of shape (frames, 3) representing camera motion vectors.

Returns:

A (frames, 6) array representing the constraint vectors for each frame.

Return type:

np.ndarray

gT1(a, b)[source]

Constructs a vector used in solving the quadratic equations for factorization based on Tomasi/Kanade and Poelman/Kanade methods.

Parameters:
  • a (np.ndarray) – A vector of shape (3,) representing the motion of the first frame.

  • b (np.ndarray) – A vector of shape (3,) representing the motion of the first frame.

Returns:

A vector of shape (6,) containing the constraint terms.

Return type:

np.ndarray

print_rotation_angles(R, name='SC')[source]

Prints rotation angles for each rotation matrix in degrees.

Parameters:
  • R (numpy.ndarray) – Rotation matrices array, shape (num_cameras, 3, 3).

  • name (str, optional) – Name to prefix the print statements (default is ‘SC’).

Returns:

List of rotation angles [phiX, phiY, phiZ] in degrees for each rotation matrix.

Return type:

list of numpy.ndarray

print_scaling_factors(scaling_factors)[source]

Normalizes and prints the relative scaling factors of each view.

Parameters:

scaling_factors (numpy.ndarray) – Scaling factors for each camera view.

Returns:

Normalized scaling factors with respect to the normalized view.

Return type:

numpy.ndarray

remove_outliers_repro(W, reW, thFac)[source]

Removes outlier points based on reprojection error by applying a threshold.

Parameters:
  • W (np.ndarray) – The original 2D measurement matrix of shape (2*num_views, num_points).

  • reW (np.ndarray) – The reprojected 2D measurement matrix of shape (2*num_views, num_points).

  • thFac (float) – The reprojection error threshold in pixels.

Returns:

  • Wnew (np.ndarray): Cleaned measurement matrix after removing outliers.

  • WreNew (np.ndarray): Corresponding reprojected measurement matrix.

Return type:

tuple of np.ndarray

reprojected_measurement_matrix(result)[source]

Reprojects the 3D structure back to 2D image space using the estimated camera rotations and scaling.

Parameters:

result (tuple) – The factorization result containing: - rotations (list of np.ndarray): Camera rotation matrices. - structure (np.ndarray): 3D structure. - scalings (list of float): Scaling factors per image. - params (tuple): Affine parameters (c, s).

Returns:

  • reW (np.ndarray): The reprojected 2D measurement matrix of shape (2*num_views, num_points).

  • P_trunc (list of np.ndarray): List of projection matrices for each view.

Return type:

tuple

rotation_angles_arctan(R)[source]

Extract rotation angles (in degrees) from a rotation matrix using arctangent.

Parameters:

R (numpy.ndarray) – A 3x3 rotation matrix.

Returns:

Rotation angles [x, y, z] in degrees.

Return type:

numpy.ndarray

show()[source]

Prints the estimated rotation angles for each face.

signed_error(reW, W)[source]

Computes the signed reprojection error between the reprojected and original measurement matrices.

Parameters:
  • reW (np.ndarray) – The reprojected 2D measurement matrix of shape (2*num_views, num_points).

  • W (np.ndarray) – The original 2D measurement matrix of shape (2*num_views, num_points).

Returns:

A (2, num_points) array containing the signed errors in u and v directions.

Return type:

np.ndarray