University at Buffalo
Department of Computer Science and Engineering
CSE 473/573 - Computer Vision and Image Processing
Fall 2023
Project #1
Due Date: 10/16/2023, 11:59PM
1 Rotation Matrix (4 points)
Figure 1 illustrates the transformation from coordinate xyz to XYZ: 1) rotate around z axis with α
(the current coordinate is x’y’z’); 2) rotate around x′ axis with β (the current coordinate is x”y”z”);
3) rotate around z′′ axis with γ (the current coordinate is XYZ). α, β, and γ are all given in angles
(not radians), and 0◦ < α, β, γ < 90◦
.
• Design a program to get the rotation matrix from xyz to XYZ. (2 points)
• Design a program to get the rotation matrix from XYZ to xyz. (2 points)
Figure 1: Illustration of Eular angles
We may test your code using different α, β, and γs in grading.
2 Camera Calibration (6 points)
Preliminary.1.
The projection from world coordinate to image plane can be indicated by intrinsic parameters
/(Camera) and extrinsic parameters(World). From world coordinate to camera coordinate, the
extrinsic parameters can be used as
Let XwYwZw be the world coordinate and xy be the image coordinate, we have the transformation
matrix M ∈ R
We can solve mij with the equation below:
where the first matrix is with size 2n × 12 (n is the number of available points).
We apply Equation (9) to calculate m = {mij}. Specifically, x = λm denotes the direction of
m, where ∥x∥ = 1. If we know the values of λ and x, we can get m. To obtain the value of x,
applying Equation (9). To obtain the value of λ, we have ||m3|| = || 1
λ
x3|| = 1.
Preliminary.3.
Solve the homogeneous linear equation Ax = 0, where x is the vector of N unknowns, and A is the
matrix of M × N coefficients. A quick observation is that there are infinite solutions for Ax = 0,
since we can randomly scale x with a scalar λ such that A(λx) = 0. Therefore, we assume ∥x∥ = 1.
Solving the equation can be converted to
min ∥Ax∥ (9)
The minimization problem can be solved with Singular Value Decomposition (SVD). Assume that
A can be decomposed to UΣVT
, we have
min ∥Ax∥ = ∥UΣVT x∥ = ∥ΣVT x∥. (10)
Note that ∥VT x∥ = ∥x∥ = 1, then let y = VT x, so we have
min ∥Ax∥ = ∥Σy∥
Question
Figure 2 shows an image of the checkerboard, where XY Z is the world coordinate and xy is marked
as the image coordinate. The edge length of each grid on the checkerboard is 10mm in reality.
Suppose one pixel of the image is equivalent to 1mm. You can calculate the projection matrix from
world coordinate to image coordinate based on the 32 corners (marked points) on the checkerboard
(16 corners in each side of the checkerboard). From the projection matrix you can get the intrinsic
matrix which is indicated as
fx 0 ox
0 fy oy
0 0 1
(fx and fy are not necessarily be equal).
• Design a function to get the image coordinates of the 32 corners from the image. You can
decide the order of output points for yourself. (2 point)
• Manually (or design a program) to get the world coordinate of the 32 corners. Note that the
output order should be the SAME with the last question. (1 point)
• Design a function to get the intrinsic parameters fx, fy, ox, oy from the image coordinates
and world coordinates acquired above. (2 points)
• Design a function to get the extrinsic parameters R, T from the image coordinates and world
coordinates acquired above. (1 points)
Figure 2: Image of the checkerboard
Instructions (Please read this very carefully!):
• You are only allow to use OpenCV version 4.5.4 for this project.
/• Please implement all your code in file “UB Geometry.py”. Please do NOT make any
changes to any file except “UB Geometry.py”.
• To submit your code and result, Please run “pack submission.sh ” to pack your code and
result into a zip file. You can find the command line in “README.md” Note that when
packing your submission, the script would run your code before packing. The resulting zip
file is only file you need to submit. You should upload the resulting zip file in Brightspace
(UBlearns).
• The packed submission file should be named “submission < Y our UBIT name >.zip”,
and it should contain 3 files, named “result task1.json”, “result task2.json”, and
“UB Geometry.py”. If not, there is something wrong with your code/filename, please go
back and check.
• You are ONLY allowed to use the library that are already imported in the script.
• We grade this project based on the results we get from running your code. If you do not give
correct final results, you are very likely to get NO partial points for that step, even if it may
because you did the former parts wrong.
• Late submissions are NOT accepted.
• Anyone whose raise “RuntimeError”, your grade will be 0 for that task.
• Anyone whose code is evaluated as plagiarism, your grade will be 0 for this project.