The aniposelib API reference¶
The “Cameras” module¶

class
aniposelib.cameras.
Camera
(matrix=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), dist=array([0., 0., 0., 0., 0.]), size=None, rvec=array([0., 0., 0.]), tvec=array([0., 0., 0.]), name=None, extra_dist=False)¶ Bases:
object

get_dict
()¶

load_dict
(d)¶

from_dict
()¶

get_camera_matrix
()¶

get_distortions
()¶

set_camera_matrix
(matrix)¶

set_focal_length
(fx, fy=None)¶

get_focal_length
(both=False)¶

set_distortions
(dist)¶

set_rotation
(rvec)¶

get_rotation
()¶

set_translation
(tvec)¶

get_translation
()¶

get_extrinsics_mat
()¶

get_name
()¶

set_name
(name)¶

set_size
(size)¶ set size as (width, height)

get_size
()¶ get size as (width, height)

resize_camera
(scale)¶ resize the camera by scale factor, updating intrinsics to match

get_params
()¶

set_params
(params)¶

distort_points
(points)¶

undistort_points
(points)¶

project
(points)¶

reprojection_error
(p3d, p2d)¶

copy
()¶


class
aniposelib.cameras.
CameraGroup
(cameras, metadata={})¶ Bases:
object

subset_cameras
(indices)¶

subset_cameras_names
(names)¶

project
(points)¶ Given an Nx3 array of points, this returns an CxNx2 array of 2D points, where C is the number of cameras

triangulate
(points, undistort=True, progress=False)¶ Given an CxNx2 array, this returns an Nx3 array of points, where N is the number of points and C is the number of cameras

triangulate_possible
(points, undistort=True, min_cams=2, progress=False, threshold=0.5)¶ Given an CxNxPx2 array, this returns an Nx3 array of points by triangulating all possible points and picking the ones with best reprojection error where: C: number of cameras N: number of points P: number of possible options per point

triangulate_ransac
(points, undistort=True, min_cams=2, progress=False)¶ Given an CxNx2 array, this returns an Nx3 array of points, where N is the number of points and C is the number of cameras

reprojection_error
¶ Given an Nx3 array of 3D points and an CxNx2 array of 2D points, where N is the number of points and C is the number of cameras, this returns an CxNx2 array of errors. Optionally mean=True, this averages the errors and returns array of length N of errors

bundle_adjust_iter
(p2ds, extra=None, n_iters=10, start_mu=15, end_mu=1, max_nfev=200, ftol=0.0001, n_samp_iter=100, n_samp_full=1000, error_threshold=0.3, verbose=False)¶ Given an CxNx2 array of 2D points, where N is the number of points and C is the number of cameras, this performs iterative bundle adjustsment to finetune the parameters of the cameras. That is, it performs bundle adjustment multiple times, adjusting the weights given to points to reduce the influence of outliers. This is inspired by the algorithm for Fast Global Registration by Zhou, Park, and Koltun

bundle_adjust
(p2ds, extra=None, loss='linear', threshold=50, ftol=0.0001, max_nfev=1000, weights=None, start_params=None, verbose=True)¶ Given an CxNx2 array of 2D points, where N is the number of points and C is the number of cameras, this performs bundle adjustsment to finetune the parameters of the cameras

optim_points
(points, p3ds, constraints=[], constraints_weak=[], scale_smooth=4, scale_length=2, scale_length_weak=0.5, reproj_error_threshold=15, reproj_loss='soft_l1', n_deriv_smooth=1, scores=None, verbose=False)¶ Take in an array of 2D points of shape CxNxJx2, an array of 3D points of shape NxJx3, and an array of constraints of shape Kx2, where C: number of camera N: number of frames J: number of joints K: number of constraints
This function creates an optimized array of 3D points of shape NxJx3.
Example constraints: constraints = [[0, 1], [1, 2], [2, 3]] (meaning that lengths of segments 0>1, 1>2, 2>3 are all constant)

optim_points_possible
(points, p3ds, constraints=[], constraints_weak=[], scale_smooth=4, scale_length=2, scale_length_weak=0.5, reproj_error_threshold=15, reproj_loss='soft_l1', n_deriv_smooth=1, scores=None, verbose=False)¶ Take in an array of 2D points of shape CxNxJxPx2, an array of 3D points of shape NxJx3, and an array of constraints of shape Kx2, where C: number of camera N: number of frames J: number of joints P: number of possible options per point K: number of constraints
This function creates an optimized array of 3D points of shape NxJx3.
Example constraints: constraints = [[0, 1], [1, 2], [2, 3]] (meaning that lengths of segments 0>1, 1>2, 2>3 are all constant)

triangulate_optim
(points, init_ransac=False, init_progress=False, **kwargs)¶ Take in an array of 2D points of shape CxNxJx2, and an array of constraints of shape Kx2, where C: number of camera N: number of frames J: number of joints K: number of constraints
This function creates an optimized array of 3D points of shape NxJx3.
Example constraints: constraints = [[0, 1], [1, 2], [2, 3]] (meaning that lengths of segments 0>1, 1>2, 2>3 are all constant)

copy
()¶

set_rotations
(rvecs)¶

set_translations
(tvecs)¶

get_rotations
()¶

get_translations
()¶

get_names
()¶

set_names
(names)¶

average_error
(p2ds, median=False)¶

calibrate_rows
(all_rows, board, init_intrinsics=True, init_extrinsics=True, verbose=True, **kwargs)¶

get_rows_videos
(videos, board, verbose=True)¶

set_camera_sizes_videos
(videos)¶

calibrate_videos
(videos, board, init_intrinsics=True, init_extrinsics=True, verbose=True, **kwargs)¶ Takes as input a list of list of video filenames, one list of each camera. Also takes a board which specifies what should be detected in the videos

get_dicts
()¶

from_dicts
()¶

from_names
(fisheye=False)¶

load_dicts
(arr)¶

dump
(fname)¶

load
()¶

resize_cameras
(scale)¶

The “Boards” module¶

class
aniposelib.boards.
CalibrationObject
¶ Bases:
abc.ABC

class
aniposelib.boards.
CharucoBoard
(squaresX, squaresY, square_length, marker_length, marker_bits=4, dict_size=50, aruco_dict=None, manually_verify=False)¶

class
aniposelib.boards.
Checkerboard
(squaresX, squaresY, square_length=1, manually_verify=False)¶

aniposelib.boards.
extract_points
(merged, board, cam_names=None, min_cameras=1, min_points=4, check_rtvecs=True)¶ Takes a list of merged rows (output of merge_rows) and a board object. Returns an array of object points and another array of image points, both of size CxNx2, where C is the number of cameras, N is the number of points. Optionally takes a list of cam_names, which determines what the keys are for each row. If cam_names are not given, then it is automatically determined from the rows, used in sorted order. It also takes a parameter min_cameras, which specifies how many cameras must see a point in order to keep it.

aniposelib.boards.
extract_rtvecs
(merged, cam_names=None, min_cameras=1, board=None, cameras=None)¶ Takes a list of merged rows (output of merge_rows) and a board object. Returns an array of rvecs and tvecs appended together, of size CxNx6, where C is the number of cameras, N is the number of detections. Optionally takes a list of cam_names, which determines what the keys are for each row. If cam_names are not given, then it is automatically determined from the rows, used in sorted order. It also takes a parameter min_cameras, which specifies how many cameras must see a point in order to keep it.
board.estimate_pose_rows should have been run on the rows before merging. If not, the board and cameras must be passed as arguments.

aniposelib.boards.
merge_rows
(all_rows, cam_names=None)¶ Takes a list of rows returned from detect_images or detect_videos. Returns a merged version of the rows, wherein rows from different videos/images with same framenum are grouped. Optionally takes a list of cam_names, which determines what the keys are for each row.