Introduction
In computer vision, it is a common task to map pixels in an image to a coordinate system in the real world and vice versa. The geolocation module in the airside system repository maps pixels in an image to geographical coordinates using the drone's position and orientation.
Theory
The diagram above displays the vectors used in the geolocation algorithm. The world space is the coordinate system used to describe the position of an object in the world (e.g. latitude and longitude). The world space is shown in the diagram with the black coordinate system. The camera space is the coordinate system used to describe the position of an object in relation to the camera. The camera space is showing in the diagram with vectors c, u, v. Note that bolded variables are vector quantities.
The table below outlines what each variable represents.
Vector | What it represents |
---|---|
o | The location of the camera in the world space (latitude and longitude of camera). |
c | Orientation of the camera in the world space (yaw, pitch, and roll of camera). |
u | Horizontal axis of the image in the camera space (right is positive). |
v | Vertical axis of the image in the camera space (down is positive). |
To compute the geographical coordinates (latitude and longitude) of a pixel in an image, we need to convert a pixel in the image (p1, p2) → vector in the camera space (p) → vector in the world space (a).
We can compute the scaling factor (let’s call the scaling factor t) with the equation below.
Rotation Matrix
It is useful to think about a matrix as a transformation in space. A matrix can warp the coordinate system into a different shape. When we multiply a vector with a matrix, we can visually see this as transforming a vector from one coordinate space to another. To better understand matrices as transformations, you can look at the resources below.
A rotation matrix is a special type of matrix, as it transforms the coordinate space by revolving it around the origin. A visualization of a rotation matrix can be seen below.
Rotation matrices are useful since it allows us to model the orientation of an object in 3D space. Multiplying a vector with a rotation matrix allows us to rotate a vector and change its orientation. The rotation matrices for 3D space are shown below. For more information on rotation matrices, see here: https://en.wikipedia.org/wiki/Rotation_matrix
Intrinsic Camera Properties
Pixels and the Camera Space
You can think of an image as a grid of pixels. Pixels are the smallest component in a digital image. The resolution of an image is the number of pixels in an image. The top-left pixel in the image is the origin (the point (0, 0)). The positive x-direction points in the right direction and the positive y-direction points downwards.
The camera coordinate system follows the North-East-Down (NED) coordinate system. In the NED system, the x-axis is the forward direction, the y-axis is the rightward direction, and the z-axis the downward direction. In the camera coordinate system, c corresponds to the x-direction, u corresponds to the y-direction, and v corresponds to the z-direction. See more information about the NED system here: https://en.wikipedia.org/wiki/Local_tangent_plane_coordinates.
Calculating Camera Space Vectors
Pixel to Vector in Camera Space
To map a pixel to its corresponding vector in the camera space we use the scaling function shown below.
From the following calculations we can see that the codomain of the scaling function is [-1, 1] (the maximum value of the function is 1 and the minimum value of the function is -1). We can multiply the value of the scaling function with the vectors u and v to get the horizontal and vertical axis of the pixel vector (upixel = f(p, r) * u and vpixel = f(p, r) * v). Thus the pixel vector (p) is equal to c + upixel + vpixel.
Extrinsic Camera Properties
Before we can convert vectors in the camera space to vectors in the world space, we need to know how the camera is positioned in relation to the drone. We need to know the position of the camera in relation to the drone and the orientation of the camera in relation to the drone. The position and orientation of the camera is reported in the NED coordinate system.
When calculating the position of the camera in relation to the drone, the measurements must be reported in meters from the center of the drone. When calculating the orientation of the camera in relation to the drone, the measurements must be reported in radians when the drone is on a flat surface.
Geolocation
The Geolocation
class in the airside system repository is responsible for converting a pixel in the image space to coordinates in the NED system in the world space. Geolocation works by creating a perspective transform matrix that maps pixels to coordinates in the real world. Below is a list of drop down menus explaining the helper functions used in the geolocation algorithm.
Now that we have described how the functions in the Geolocation
class works, we can go through the run
function and see how the entire algorithm works.
Get the
MergedOdometeryDetection
object from the queue and create the rotation matrix that models the drone’s orientation with the drone’s yaw, roll, and pitchGet the home location from the
home_location_queue
and the drone’s location from theMergedOdometryDetection
object and pass it into thedrone_position_local_from_global
function to get the drone’s location in the NED coordinate system.Pass in the drone’s rotation matrix and the drone’s position in the NED system to the
__get_perspective_transform_matrix
function to get the perspective transform matrix.Pass in the perspective transform matrix and
Detection
object into the__convert_detection_to_world_from_image
to convert the detected object into coordinates in the world frame.Create a
DetectionInWorld
object and output it in the output queue.