|
2 | 2 |
|
3 | 3 | [](https://app.travis-ci.com/pvphan/camera-calibration)
|
4 | 4 |
|
5 |
| -A simple library for calibrating camera intrinsics from a json file of sensor (2D) and model point (3D) correspondences. |
6 |
| -Written primarily as an exercise with few external dependencies (numpy, sympy, imageio) for a deeper understanding. |
| 5 | +A simple library for calibrating camera intrinsics from sensor (2D) and model point (3D) correspondences. |
| 6 | +Written with few external dependencies (numpy, sympy, imageio) for a deeper understanding. |
7 | 7 | Also generates synthetic datasets for testing and rudimentary visualization.
|
8 | 8 |
|
9 | 9 | Prerequisites: `make`, `docker`
|
10 | 10 |
|
11 | 11 |
|
12 | 12 | ## TODO:
|
13 | 13 |
|
14 |
| -- [x] Generate dataset to test on (dataset.py) |
15 |
| -- [x] From 2D / 3D feature correspondences, estimate the homography (DLT-like estimation) |
16 |
| -- [x] Compute close form solution for K based on homographies (ignore lens distorion) |
17 |
| -- [x] Compute extrinsics R, t for each view |
18 |
| -- [x] Compute distortion using linear least squares |
19 |
| -- [x] Use estimated parameters as initial guess and refine using non-linear optimization over all views |
20 |
| -- [x] Write main method interface for calibrating from json files |
21 |
| -- [x] Support full radial-tangential distortion model |
22 |
| -- [x] Write nonlinear optimization by hand instead of using SciPy |
23 |
| -- [ ] Try vectorizing the Jacobian computation (takes ~14 sec per iteration of LM currently) |
24 |
| -- [ ] Button up as python package |
| 14 | +- [ ] Vectorize the Jacobian computation (takes ~14 sec per iteration of Levenberg-Marquardt currently) |
| 15 | +- [ ] Button up as python package, add instructions to README |
25 | 16 | - [ ] Support fisheye distortion model
|
26 | 17 |
|
27 | 18 |
|
28 |
| -## Notes: |
29 |
| -- Need 6 points to find transform matrix P in the equation x = P * X. 11 unknowns, each point gives 2 variables, so 11 / 2 = 5.5 ~= 6 |
30 |
| -- P = [H | h] |
31 |
| -- X0 = -H^-1 * h |
32 |
| -- To decompose H = KR into the intrinsic and rotation matrices, use QR-decomposition. |
33 |
| - - In QR-decomposition, Q is a rotation matrix, R is a triangular matrix. |
34 |
| - - H^-1 = (K * R)^-1 = R^-1 * K^-1 = R^T * K^-1 |
35 |
| - - Q = R^T |
36 |
| - - R = K^-1 |
37 |
| - - Need to normalize K, e.g. K = 1/K33 * K |
38 |
| - - Need to do a coordinate tranform by a rotation of 180 deg |
39 |
| - - K = K * R(z, 180) |
40 |
| - - R = R(z, 180) * R |
41 |
| - |
42 |
| -- DLT in a nutshell |
43 |
| - 1. Build M for the linear system: M is (2 * i, 12) and p is (12, 1). M * p = 0. |
44 |
| - For every point we measure, we add 2 rows to the matrix M (minimum of 6 points which is 12 rows). |
45 |
| - |
46 |
| - 2. Solve by SVD M = U S V^T, solution is the last column of V, which are the values of p which gives us P. |
47 |
| - 3. Solve for K, R, X0. Let P = [H | h] |
48 |
| - - X0 = -H^-1 * h |
49 |
| - - QR(H^-1) = R^T * K^-1 |
50 |
| - - R = R(z, 180) * R |
51 |
| - - K = (1/K33) * K * R(z, 180) |
52 |
| - |
53 |
| -- What were the innovations of Zhang calibration over the prior state of the art? |
54 |
| - |
55 |
| - - Previous calibration techniques required more expensive or procedures: specially made 3D calibration targets, or targets that are moved in a precise way. |
56 |
| - - Zhang's method requires only a 2D planar target (cheap to print) and requires no special movements |
57 |
| - |
58 |
| -- Under what conditions will this calibration method fail? |
59 |
| - |
60 |
| - - If the calibration target undergoes pure, unknown translation, Zhang's method will not work. |
61 |
| - - This is because additional views on the same model plane do not add additional constraints. |
62 |
| - - But if the translation of the target is precisely known, then calibration is possible if we impose those constraints. |
63 |
| - |
64 |
| -- At a high level, what are the steps to the Zhang calibration algorithm? |
65 |
| - |
66 |
| - - Collect feature points (2D / 3D point associations) from several images (assumed to be done) |
67 |
| - - Estimate the intrinsic and extrinsic parameters using the closed form solution |
68 |
| - - Estimate the radial distortion parameters |
69 |
| - - Refine all parameters by minimizing |
70 |
| - |
71 |
| -- What is SVD, DLT, and QR, and how do they relate to Zhang calibration? |
72 |
| - |
73 |
| - - In the DLT case, QR-decomposition is used to decouple the intrinsics (K) and the rotation matrix (R) from the full projection matrix P. |
74 |
| - - But in Zhang's method, we cannot use QR-decomposition because the product contains the intrinsic matrix and a matrix which is not orthogonal (r1, r2, t) |
75 |
| - - x = P * X, P = [H | h], H = K * R |
76 |
| - - QR-decomposition separates H into its two products: an orthogonal matrix (the rotation matrix, R) and an upper-diagonal matrix (the intrinsic matrix, K) |
77 |
| - - Instead, we will drop the z terms (every 3rd col) of the linear system and solve for the 3x3 homography H |
78 |
| - |
79 |
| - - Still need to estimate K from H: H = K * [r1 r2 t]. So we need a custom solution to exploit properties we know about K, r1, and r2 |
80 |
| - 1. Exploit constraints on K, r1, r2 |
81 |
| - 2. Define a matrix B = K^-T * K^-1 |
82 |
| - 3. Compute B by solving another homogeneous linear system |
83 |
| - 4. Decompose matrix B to get K |
84 |
| - |
85 |
| - |
86 | 19 | ## References:
|
87 | 20 | - (paper) [Wilhelm Burger: Zhang's Camera Calibration Algorithm: In-Depth Tutorial and Implementation](https://www.researchgate.net/publication/303233579_Zhang's_Camera_Calibration_Algorithm_In-Depth_Tutorial_and_Implementation).
|
88 | 21 | - (paper) [Zhengyou Zhang: A Flexible New Technique for Camera Calibration](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/tr98-71.pdf)
|
|
0 commit comments