AI Hero Club

Computer Vision and 3D Scenes · Lesson 3

Marked Complete by You0 / 8

Saved in this browser only. Marking a lesson complete does not mean the project has passed verification.

Lesson Outline 6 subsections
Course Contents 8 lessons
Full course plan.
Computer Vision and 3D Scenes / Learning Plan ↗

LESSON 03 / 8Suggested study 120 minutes

Estimate General Camera Matrices from Calibrated Images

Given 3D targets and pixel correspondences, how do we build DLT constraints and detect degenerate inputs that cannot determine a camera?

3 Questions for This Lesson
  • Create linear constraints for non-communist targeting
  • Decomposition to uniform DLT and inversely normalized
  • Identification of differences between degradation, algebra error and pixel error
Course Project ZIP ↓

Calibration Constraints, Normalization, and Camera Identifiability

Chapter II uses the camera matrix as a known input, and this chapter estimates it with an independent photograph. The marked target is 16 colour markers of known three-dimensional locations at the time of manufacture, with coordinates recorded in rice; the coordinates of unknown bead scenes are not provided to the labeler. The detector automatically extracts the area from each marked PNG, and the colour description matches the known colour of the target, so that the known geometry is a measurement tool, not the true value of the unknown object. The marked target error also enters the result and this synthesizer idealizes it to be accurate.

The matrix P has 12 elements to be estimated, but the overall non-zero ratio does not affect pixels, so there is 11 separate degrees of freedom for the projectors in general. Each three-dimensional to two-dimensional corresponds to two separate linear constraints, so that at least six points are necessary. If all points are common, the image can only bind the plane to a single response to the image, and it cannot fully determine the image of the off-plan. The application check point set minus the mean number three and then enter DLT; this does not mean that all pools close to the common mass are stable.

A three-dimensional point is a four-dimensional vector. P The three rows are shown separately as column vectors p. I, p. II, p. III. The visual u is equal to the third row point at the first row, v the same. Move the denominator to the left, get the first row point at the top, u by the third line point at zero, and the second line point at the end of the second row v by the third line at zero. P, the elements are in a row to a twelve-dimensional unknown vector, with two-line design matrix for each corresponding contribution A. Constraint is numerous, and the zero matrix meets the equation, but it doesn't have camera significance.

(p1⊤−up3⊤)X~=0,(p2⊤−vp3⊤)X~=0,min⁡∥p∥=1∥Ap∥2(p_1^\top-u p_3^\top)\tilde X=0,\quad(p_2^\top-v p_3^\top)\tilde X=0,\qquad \min_{\|p\|=1}\|Ap\|^2
p is a row-by-line twelve-dimensional vector for P, excluding the zero-sum.

When there is no noise and there is sufficient configuration, the design matrix has a zero-dimensional space; when there are detection errors, there is usually no strict zero-space and instead search for vectors to minimize algebraic residues. Here the value conclusion of the import of the odd value decomposition is that A is equal to U by non-negative anomalous values and then by V by switching, so that the orthodox transformation maintains the length of the Euros, so that the minimum residue corresponds to the right odd direction of the least odd. Take V and reverse the last line and restore three times four shapes. This algebra target is easy to calculate, but it is not yet the original pixel re-projected target.

First, why are the world coordinates first unicoded? The world coordinates may be written in millimeters in thousands, pixel coordinates in hundreds, constants in one series, and the scales of each column of the matrix are very far apart. The errors in the limited precision linear algebra may be magnified, and the algebra target may also determine the weight of different items in units. We move the two-dimensional level to zero, then scale it together, so that the average E-radial radius is root two; and the three-dimensional radius is root three. This is an average distance, not the root number after the square average, and the two must be consistent.

Xn=TXX~,xn=Txx~,Pn=TxPTX−1,P=Tx−1PnTXX_n=T_X\tilde X,\quad x_n=T_x\tilde x,\quad P_n=T_xPT_X^{-1},\qquad P=T_x^{-1}P_nT_X
The matrix is first sought in the standardized coordinates and then restored to the original coordinates; the sequence of the matrices is determined by the intergenerational relationship.

Inversely, the order of homogenization can be verified directly. The original world ' s double point is first multiplied by T_X, and it is unicoded by P_n, which sends it to the unicoded pixels, and then to T_x, which reverses the original pixels. So the full map is a multiplier of the opposite T_x, P_n, T_X. It is not possible to put both changes on the left. The matrix remains fully measured and free; the project uses the first three paradigms in the third row to one, check the target 's average depth symbol and, if necessary, take the whole load and fix the forward agreement.

A Complete Numerical Construction: Eight Points and Sixteen Equations

The camera takes P=[[2,0,0,0], [0,2,0,0], [0,0,1,0]], the pixel main point is zero, the focal range is two, and the world point unit is rice. Eight points are X, Y, plus or minus one, Z, or five, and are not the same plane. This is only a small focal distance for hand calculations; the actual PNG project is still 95 pixels, not modified by this calculation.

PointXYZu=2X/Zv=2Y/Z
11132/32/3
2−113−2/32/3
31−132/3−2/3
4−1−13−2/3−2/3
51152/52/5
6−115−2/52/5
71−152/5−2/5
8−1−15−2/5−2/5
Two lines of independent perimetry are bound at each point; all observations are generated by the same clear camera.

Stores each pointed sub-coordinate q= [X,Y,Z,1] in row, with row A in row [q,0,0,0,0,−u q] and row V in row [0,0,0,0,q,−v q]. For example, the action of the u at the first point is [1,1,3,1,0,0,0,0,−2/3,−2/3,−2,−2/3]; v act [0,0,0,0,1,1,3,1,−2/3,−2/3,−2,−2/3]. The action of the u at the second point is [−1,1,3,1,0,0,0,0,−2/3,2/3,2,2/3], v act [0,0,0,0,−1,1,3,1,2/3,−2/3,−2,−2/3]. The four lines clearly identify the symbols, the order of the rows and the number of serials to each element.

The remaining six points will be added to the same rule. Got it. 16×12 Matrix. When there is no noise, it should be 11, and zero space is only one direction for the whole scale. The length of the E-form is three after the P-line, so SVD may return positive or negative. [2,0,0,0,0,2,0,0,0,0,1,0] / 3 We end with the third line, one, restoring P in the table instead of imposing the first SVD vector.

The three-dimensional mean value of this group point is: 0, 0, 4 ) All points mean value is root number 3, so TX only reduces Z by four and does not require additional scaling. Pixel mean value is zero, with an average radius of 8 root number 2/ 15 So the two pixels of Tx are scaled 15/8. by Pn=Tx P TX Reverse, get Pn= [[15/4,0,0,0], [0,15/4,0,0], [0,0,1,4] ], the common non-zero ratio is still allowed.

Standalone ProgramIndependent SVD reconstructs a clear camera and non-participating projection; project DLT is not called.
import numpy as np
P=np.array([[2.,0,0,0],[0,2,0,0],[0,0,1,0]])
X=np.array([[x,y,z,1.] for z in [3.,5.] for y in [1.,-1.] for x in [1.,-1.]])
def pixels(camera,points):
    q=points@camera.T
    return q[:,:2]/q[:,2:3]
uv=pixels(P,X)
# 从正文的两行规则构造;不导入项目calibrate_dlt。
A=np.array([row for q,(u,v) in zip(X,uv)
            for row in [np.r_[q,np.zeros(4),-u*q],np.r_[np.zeros(4),q,-v*q]]])
assert np.linalg.matrix_rank(A)==11
_,singular,Vt=np.linalg.svd(A)
Q=Vt[-1].reshape(3,4);Q=Q/Q[2,2]
np.testing.assert_allclose(Q,P,atol=1e-12)
TX=np.eye(4);TX[2,3]=-4
Tx=np.diag([15/8,15/8,1.])
Pn=np.array([[15/4,0,0,0],[0,15/4,0,0],[0,0,1,4.]])
restored=np.linalg.inv(Tx)@Pn@TX
np.testing.assert_allclose(restored,P,atol=1e-14)
heldout=np.array([[.3,-.4,4.,1.]])
np.testing.assert_allclose(pixels(Q,heldout),[[.15,-.2]],atol=1e-12)
print('rank',np.linalg.matrix_rank(A),'smallest singular',singular[-1])
print('camera',Q.tolist(),'heldout',pixels(Q,heldout).tolist())

A Coplanar False Solution with Two Concrete Camera Matrices

P=[200002000010],P′=[201/2−202000010]P=\begin{bmatrix}2&0&0&0\\0&2&0&0\\0&0&1&0\end{bmatrix},\qquad P^{\prime}=\begin{bmatrix}2&0&1/2&-2\\0&2&0&0\\0&0&1&0\end{bmatrix}
Both matrices are triple; their differences happen to be offset on the z=4 plane.

P "The lateral molecules are more than P." Z/2−2 Yes. Z=4 (a) Zero increment, so that any point in the plane is projected; X=1 、 Y=0 、 Z=5 When, "P" u=.4 , P Here. u=.5 Pixels. Both cameras perfectly explain the same plane observation, but give different answers to the point of view. That's it. “More homogeneity is still not helping.” Specific degrees of freedom.

Standalone ProgramThe two flat cameras are a number-by-number reverse.
import numpy as np
P=np.array([[2.,0,0,0],[0,2,0,0],[0,0,1,0]])
Q=P.copy();Q[0,2]=.5;Q[0,3]=-2
plane=np.array([[1.,0,4,1],[-2.,1,4,1],[.3,-.7,4,1]])
def project(M,X):
    y=X@M.T
    return y[:,:2]/y[:,2:3]
np.testing.assert_allclose(project(P,plane),project(Q,plane),atol=1e-14)
other=np.array([[1.,0,5,1]])
assert abs(project(P,other)[0,0]-.4)<1e-14
assert abs(project(Q,other)[0,0]-.5)<1e-14
print('same-plane equality; heldout difference',project(Q,other)-project(P,other))

Example 1: Reversible Denormalization and Unit Changes

A two-dimensional reclassification of pixels minus one hundred, fifty times zero one, and three-dimensional reclassification of world points minus centre two. If the camera has already been tried to be unicoded, mapping the original three-dimensional points in each of these three steps should be separated by the same scale as the directly restored P. The test does not need to know the camera's real posture, but it needs to compare the two computational paths with the random non-participating points. If the result is different, the first check is the matrix multiplying sequence with the row storage instead of recombinating the strange variants.

Reverse all world target coordinates from rice to millimeters, divide the top three columns of the camera matrix accordingly by a thousand, and move the arrays relatively, so that the total number of arrays remains constant; the overall matrix values can be multiplied by common factors. The heavy projection does not mean that units of triangular output remain constant, and the new output will be millimetres. The project agrees to save input units with coordinates, and then a comparison of three-dimensional errors requires unit unification, and the difference between rice and millimeters cannot be increased by 1,000 times the accuracy of the algorithm.

After assessing P, calculates geometrical residues: re-plug each known three-dimensional point into a pixel, re-declining the detection position, 2-dimensional squared averaged to open root numbers. This RMS uses a 2-dimensional error at every point and cannot be confused with the root number of each coordinates MSE. It also saves point-by-point errors and image locations, checking if the fragments are large on the edge and if there are a few errors matching that are evenly concealed. The five project-marked RMS pixels from 00:022 to 00:229 are controlled clean markings and not realistic camera accuracy commitments.

Example 2: A Small Algebraic Residual with an Incorrect Camera

Assuming that the depth of all known points is four metres. The third fraction of the three-dimensional points is always four times the fourth fraction, and the relevant columns of the design matrix cannot distinguish between certain camera coefficients. P This is not a loss of independent information that can be solved by collecting thousands of similar points. Multiple gestures are required to mark the inner-access constraint, or the non-combined target used by the project to restore the normality. P 。

Another independent degradation comes from the side of pixels: while the world point is not a common face, if an erroneous observation falls all in the same straight line of the image, it may be used to obtain a dichotomy rather than a valid trio camera. The new realization requires N×3 to match the number of lines with N×2, all numbers are limited, and the space for the examination of the uniform world point and two-dimensional pixels has to be expanded; sub-surreal values of the matrix must be kept in proportion to the maximum value, and finally the relative singularity of the left 3×3 block of the camera is checked for restoration. The smallest odd value cannot be seen to be close to zero, because a legal combination is supposed to have a zero-direction and the risk of degradation is a second unbridled direction.

The teaching achieves a clear use of the normalized space scale threshold: World/Pixel Expanding and Designing Sub-Small Strange Values 1e−8, the left block of the camera is 1e−10. They are numerically recognizable strategies, not the best statistical thresholds under all noise models. Normalization reduces the impact of the metre/mm and pixel scales; direct judgement is not unified in the same order. “Less than certain constant” The new regressions contain non-combined world-plus pixels, repeated observations, near-combined/near-combined lines, wrong lines and nan, and confirm that the original normally marked camera remains unchanged.

Even if not strictly in common, the design matrix may be pathological if the markers change only in a very thin depth. The relative size of the two odd values at the end, the range of target space coverage, and sensitivity to pixel disturbances should be seen together. The smallest singularity indicates only a similar interpretation and does not guarantee that the solution will stabilize the noise. A fixed seed is disturbed by zero pixels, remarked, and then looked at a heavy projection change at the point where it is set aside is a specific pressure test; it gives numerical evidence, not a universal margin of error.

General P estimates that it does not directly guarantee the desired zero-slashed entanglement form of the left three times three parts. To extract K, R, t, the left block can be decompositioned with RQ, resized with an angle symbol and rotation line, and set with one the inner bottom element; this is another binding camera interpretation step. Triangulation of this project requires only P, which is controlledly rendered using a public focal scale and does not achieve full and internal participation in the true lens for the nonlinear marking of the total involvement of mutineing. The arbitrary matrix of DLT output cannot be defaulted to satisfy all practical constraints.

Further refining usually minimizes the pixel heavy projection squares and not the algebraic residue. Using a legitimate rotation, equalization and internalization parameter to guide the parameters to an iterative pattern does not leave the rotation flow at random in optimization. Non-linear targets may be localized very small, so DLT serves as a reasonable initial value, not a guarantee of global excellence. This course explains the interface and rationale for this extension, and the current project does not pretend to run OpenCV markers or panorama beam adjustments.

The program will read the picture for each of the five cameras, including a map to keep the scene perspective. The camera parameter for the reserved perspective is derived from an independent target and does not use the reserved scenario image to adjust the bead position. This evaluation of the condition for “Stapled New Perspective” should take place instead of a completely unknown camera posture. It must be written when evaluating it, otherwise the reader may think that the project has any perspective. Unknown gestures can be used as follow-up questions, but are not currently in the range of actual tests.

The auditability and numerical stability of the source data are complementary issues. The list records the hashs for each PNG and the target file, confirming what to read; the thugs, odd values and residues check whether these inputs are sufficient to support the estimate. The correct error matching in the hash is still given to the wrong camera, and the small result may also come from the wrong unit. Receiving and inspection must be done on a layer-by-level basis along documents, observations, correspondence, matrices, residues and units, so that one does not shield other layers from failure by marking.

Run in the Project DirectoryValidate DLT with a silent projection of known general rotation cameras.
import numpy as np
from vision3d.core import look_at,project,calibrate_dlt
rng=np.random.default_rng(23)
X=rng.uniform([-1,-1,3],[1,1,5],(20,3))
P,_=look_at([.8,-.2,.1])
u,_=project(X,P)
Q,s=calibrate_dlt(X,u)
np.testing.assert_allclose(project(X,Q)[0],u,atol=1e-10)
print('reprojection max',abs(project(X,Q)[0]-u).max())

TRY IT YOURSELF

Practice I: Number of constraints

Why does a three-by-four projection camera require at least six equivalents? Is it sufficient for six equals to face it?

Hint 1
How many independent equations are provided for each of the 12 camera elements with an overall measure of freedom?
Hint 2
Counting is only a necessary condition, and the layout of the point is checked against the design matrix; more common points do not provide missing depth information.
Compare with the Solution
Eleven degrees of freedom for each of the 12 elements to remove the overall ratio; two separate constraints should be imposed on each of them after the massing subpixel scale has been removed, five to ten short and six short, but twelve short, but must be sufficient. The common point only binds the flat sheet, the depth direction and the equalisation are mutually compensating, so that no six or more common points can restore the general camera alone. The procedure examines both the quantity and the three-dimensional centralised coordinates; proximity to the common face still requires sensitivity tests.

TRY IT YOURSELF

Practice II: Inverse relativization

Known as Normalized Relationship x_n=T_x x、 X_n=T_X X, and x_n in proportion to P_n X_n. The original coordinates camera is exported gradually, without any overturning.

Hint 1
The same proportional relationship is added from two homogenization definitions to one item without first relativizing the formula.
Hint 2
Left pixel recovery requires a left-by-T_x back, right-side world point by T_X; check with two paths from the same test point.
Compare with the Solution
Replace the second definition with T_xx and P_n T_X X Proportional. Left by T_x inverse, get x and T_x- 1 }P_nT_X X Scale, so original matrix P equals the amount of the multiplier, allowing an additional non-zero ratio for the whole. The reverse to the left comes from the restoration of the pixel coordinates, and the right is being converted from the homogenization of the world coordinates first. Projecting a test point along two paths and comparing it to an independent inspection, do not take place. T_X He was also wrong to turn back.

TRY IT YOURSELF

Practice III: Target function

How can you change a single algebra DLT equation by a thousand, zero noise resolution and minimal two-fold noise interpretation? Why should you eventually report pixel residue?

Hint 1
Zero noise looks at zero space, with noise looking at the weighted target of the debris square.
Hint 2
How does the weight change when a line is magnified by 1,000? The error of pixel units is eventually measured by a different way of deciphering.
Compare with the Solution
The original equation is equal to zero with the formula of zero with 1,000 times, so the equation is ideal for unchanged. Minimizing the square of the debris in the line when the noise is heard increases the weight of the line to one million by a thousand, usually with a change in the best discount. This means that algebra targets depend on the equation scale. Normalization reduces imbalances, but it does not turn the algebra error into a pixel error; ultimately it is necessary to calculate the weight projection at each point by perimetry and to keep unit, point by point and aggregate statistics.

BUILD THE MECHANISM

To assemble DLTs from a projective equation

Achieved: Design_rows and calibrate; general SVD only, not the existing calibrate_dlt. Downloading the full project of this course, running in the project root directory; editing learner/starter.py only, with a tectonic framework provided by the project.

Input and Output At least six non-combined 3D/2D equivalents; the design matrix requires at least 11 and output camera3.
Cameras allow non-zero scale differentials and test the projection using unparticipating composite points.

Run in the Project DirectoryStudy tasks to be completed
# design_rows
def design_rows(world,pixels):
    raise NotImplementedError('dlt')

# calibrate
def calibrate(world,pixels):
    raise NotImplementedError('dlt')
Hint 1

u*(p3. X) = p1. X, V equation; two lines at each point.

Hint 2

Lines A are arranged in 12 columns by [X,0,−uX] and [0,X,−vX].

Hint 3

The smallest right odd vector reshape is 3×4; the non-combined does not automatically guarantee that the projection is visible.

Independent inspection .venv/bin/python -m learner.check --stage dlt --output runs/learner-dlt.json

Migration test Changes in the focal range and flattency of a clear P to select points not used for estimation review; noise/weak baselines can affect stability, not just re-projecting training.

Reference Implementation and Explanation
Run in the Project DirectoryReference achieved
# design_rows
def design_rows(world,pixels):
 X=np.c_[np.asarray(world,dtype=float),np.ones(len(world))];uv=np.asarray(pixels,dtype=float);rows=[]
 for point,(u,v)in zip(X,uv):rows.extend([np.r_[point,np.zeros(4),-u*point],np.r_[np.zeros(4),point,-v*point]])
 return np.asarray(rows)

# calibrate
def calibrate(world,pixels):
 world=np.asarray(world,dtype=float);pixels=np.asarray(pixels,dtype=float)
 if world.shape[0]<6 or world.shape[1:]!=(3,)or pixels.shape!=(len(world),2)or not np.isfinite(world).all()or not np.isfinite(pixels).all():raise ValueError('finite Nx3/Nx2, N>=6')
 if np.linalg.matrix_rank(np.c_[world,np.ones(len(world))])<4:raise ValueError('coplanar input')
 A=design_rows(world,pixels);u,s,v=np.linalg.svd(A,full_matrices=False)
 if np.linalg.matrix_rank(A,tol=s[0]*1e-10)<11:raise ValueError('unidentifiable camera')
 P=v[-1].reshape(3,4)
 if np.linalg.matrix_rank(P,tol=np.linalg.norm(P)*1e-10)<3:raise ValueError('rank deficient camera')
 return P/np.linalg.norm(P)

CHECK YOUR UNDERSTANDING

Check Your Understanding

Answer first, then open the explanation to check your reasoning. These questions help reveal gaps in understanding; independent implementation and transfer require separate evaluation.

1. Why is the overall proportion of the general projection matrix not determined by pixels?

Show ExplanationThe P-wide multiplying of non-zero constants does not change the unicoded pixels.
2. Six points are enough to estimate the camera's integrity?

Show ExplanationThe measurement of freedom is only a necessary condition and the design matrix determines whether it is identifiable.
3. DLT's smallest right-hand odd vector directly minimizes what?

Show ExplanationThe visual divides geometry errors from linear algebra targets.
4. The reserved perspective has been marked with an independent target. What are the conditions for the experimental verification?

Show ExplanationCamera parameters for a new perspective are provided and cannot be assumed to achieve an unknown attitude estimate.

Manual completion records your progress; it does not certify your project.