Last active
November 18, 2019 21:15
-
-
Save lambdaloop/f60849c5aa993043dc40fb893c806e15 to your computer and use it in GitHub Desktop.
Minimal calligator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from calligator.boards import CharucoBoard, Checkerboard | |
from calligator.cameras import Camera, CameraGroup | |
cam_names = ['A', 'B', 'C'] | |
# cam_names = ['A', 'B', 'C', 'D', 'E', 'F'] | |
vidname_format = 'videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test {} Cam-{}.avi' | |
vidnames = [[] for _ in cam_names] | |
for i in range(2, 4): | |
for cix, cname in enumerate(cam_names): | |
vname = vidname_format.format(i, cname) | |
vidnames[cix].append(vname) | |
# Example format here is: | |
# [['videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test 2 Cam-A.avi', | |
# 'videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test 3 Cam-A.avi'], | |
# ['videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test 2 Cam-B.avi', | |
# 'videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test 3 Cam-B.avi'], | |
# ['videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test 2 Cam-C.avi', | |
# 'videos/calibration-evyn-2019-05-22-compressed/23-May-2019 Calibration Test 3 Cam-C.avi']] | |
n_cams = len(cam_names) | |
board = CharucoBoard(6, 6, | |
square_length=0.5, # here, in mm but any unit works | |
marker_length=0.375, | |
marker_bits=4, dict_size=50) | |
# an example checkerboard usage | |
# board = Checkerboard(9, 6, square_length=2) | |
cgroup = CameraGroup.from_names(cam_names) | |
# cgroup = CameraGroup.from_names(cam_names, fisheye=True) # supports fisheye too if needed | |
# this will take a few minutes | |
# cgroup.calibrate_videos(vidnames, board) | |
# example saving and loading for later | |
# cgroup.dump('calib.toml') | |
cgroup = CameraGroup.load('calib.toml') | |
# example triangulation (of random points here for simplicity) | |
n_cams = len(cam_names) | |
n_points = 100 | |
pts = np.random.uniform(600, size=(n_cams, n_points, 2)) | |
# triangulation doc | |
# 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 | |
p3d = cgroup.triangulate(pts) | |
# example triangulation with multiple joints | |
n_cams = len(cam_names) | |
n_frames = 100 | |
n_joints = 13 | |
pts = np.random.uniform(600, size=(n_cams, n_frames, n_joints, 2)) | |
pts_flat = pts.reshape((n_cams, -1, 2)) | |
p3d_flat = cgroup.triangulate(pts_flat) | |
p3d = p3d_flat.reshape(n_frames, n_joints, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment