The goal of this exercise is to superimpose a virtual cube on a video of a planar grid viewed from different orientations. In this exercise, the 3D positions of the checkerboard, and the relative camera poses are provided, as well as the intrinsics of the camera. The purpose of this exercise is to familiarize with the basics of perspective projection, change of coordinate systems and lens distortion, as well as basic image processing with Python.
$ conda env create -f environment.yaml
$ conda activate aue8089pa2
Below figure is a reminder of the different steps involved in projecting a 3D point
Assuming the lens distortion has already been compensated (which is the case in this section), the perspective projection can be written linearly in homogeneous coordinates as shown in the lecture:
where K.txt
.
In this exercise, the rotation
where
- Write some code to create a matrix containing the 8 vertices of a cube lying on the checkerboard’s plane. The position of the cube on the checkerboard and its size should be customizable.
- Project the cube's vertices on the image and draw a line (line) for each edge of the cube.
Repeat the process above for all the images in the sequence and generate a small movie (at 20 frames per second).
Real camera lenses are not ideal and introduce some distortion in the image. To account for these non-idealities, it is necessary to add a distortion model to the equations of perspective projection. A simple radial distortion model was introduced during the lecture. In this exercise, we use this model, and simply add a higher-order term, parameterized by an additional variable D.txt
. Because the distortion model is not linear, the projection function needs to split into two steps.
- We start again by mapping the world point
$P_w$ to pixel coordinates$p = (u, v)^T$ .
- Next, we apply lens distortion to
$p$ to get the distorted pixel coordinates$p_d = (u_d, v_d)^T$ :
where
We will now use the new projection function (that takes distortion into account) to generate an undistorted image from the original image. Let
where
However, due to the undistorted pixel locations being non-integer, the resulting image would have some artifacts. Moreover, inverting the distortion function
Since
- Write a function undistort_image that performs the image undistortion and nearest-neighbor interpolation. The expected output is shown below.