Main Content

birdsEyeView

Create bird's-eye view using inverse perspective mapping

Description

Use the birdsEyeView object to create a bird's-eye view of a 2-D scene using inverse perspective mapping. To transform an image into a bird's-eye view, pass a birdsEyeView object and that image to the transformImage function. To convert the bird’s-eye-view image coordinates to or from vehicle coordinates, use the imageToVehicle and vehicleToImage functions. All of these functions assume that the input image does not have lens distortion. To remove lens distortion, use the undistortImage function.

Creation

Description

example

birdsEye = birdsEyeView(sensor,outView,outImageSize) creates a birdsEyeView object for transforming an image to a bird’s-eye-view.

  • sensor is a monoCamera object that defines the configuration of the camera sensor. This input sets the Sensor property.

  • outView defines the portion of the camera view, in vehicle coordinates, that is transformed into a bird's-eye view. This input sets the OutputView property.

  • outImageSize defines the size, in pixels, of the output bird's-eye-view image. This input sets the ImageSize property.

Properties

expand all

Camera sensor configuration, specified as a monoCamera object. The object contains the intrinsic camera parameters, the mounting height, and the camera mounting angles. This configuration defines the vehicle coordinate system of the birdsEyeView object. For more details, see Vehicle Coordinate System.

Coordinates of the region to transform into a bird's-eye-view image, specified as a four-element vector of the form [xmin xmax ymin ymax]. The units are in world coordinates, such as meters or feet, as determined by the Sensor property. The four coordinates define the output space in the (X, Y) coordinate system, with the origin centered on the location of the camera sensor.

Vehicle with camera sensor and rectangular region within the sensor view that is being transformed. Clockwise from top, the sides of the region are labeled ymax, xmax, ymin, and xmin.

You can set this property when you create the object. After you create the object, this property is read-only.

Size of output bird's-eye-view images, in pixels, specified as a two-element vector of the form [m n], where m and n specify the number of rows and columns of pixels for the output image, respectively. If you specify a value for one dimension, you can set the other dimension to NaN and birdsEyeView calculates this value automatically. Setting one dimension to NaN maintains the same pixel to world-unit ratio along the XV-axis and YV-axis.

You can set this property when you create the object. After you create the object, this property is read-only.

Object Functions

transformImageTransform image to bird's-eye view
imageToVehicleConvert bird's-eye-view image coordinates to vehicle coordinates
vehicleToImageConvert vehicle coordinates to bird's-eye-view image coordinates

Examples

collapse all

Create a bird's-eye-view image from an image obtained by a front-facing camera mounted on a vehicle. Display points within the bird's-eye view using the vehicle and image coordinate systems.

Define the camera intrinsics and create an object containing these intrinsics.

focalLength = [309.4362 344.2161];
principalPoint = [318.9034 257.5352];
imageSize = [480 640];

camIntrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);

Set the height of the camera to be about 2 meters above the ground. Set the pitch of the camera to 14 degrees toward the ground.

height = 2.1798;
pitch = 14;

Create an object containing the camera configuration.

sensor = monoCamera(camIntrinsics,height,'Pitch',pitch);

Define the area in front of the camera that you want to transform into a bird's-eye view. Set an area from 3 to 30 meters in front of the camera, with 6 meters to either side of the camera.

distAhead = 30;
spaceToOneSide = 6;
bottomOffset = 3;

outView = [bottomOffset,distAhead,-spaceToOneSide,spaceToOneSide];

Set the output image width to 250 pixels. Compute the output length automatically from the width by setting the length to NaN.

outImageSize = [NaN,250];

Create an object for performing bird's-eye-view transforms, using the previously defined parameters.

birdsEye = birdsEyeView(sensor,outView,outImageSize);

Load an image that was captured by the sensor.

I = imread('road.png');
figure
imshow(I)
title('Original Image')

Transform the input image into a bird's-eye-view image.

BEV = transformImage(birdsEye,I);

In the bird's-eye-view image, place a 20-meter marker directly in front of the sensor. Use the vehicleToImage function to specify the location of the marker in vehicle coordinates. Display the marker on the bird's-eye-view image.

imagePoint = vehicleToImage(birdsEye,[20 0]);
annotatedBEV = insertMarker(BEV,imagePoint);
annotatedBEV = insertText(annotatedBEV,imagePoint + 5,'20 meters');

figure
imshow(annotatedBEV)
title('Bird''s-Eye-View Image: vehicleToImage')

Define a location in the original bird's-eye-view image, this time in image coordinates. Use the imageToVehicle function to convert the image coordinates to vehicle coordinates. Display the distance between the marker and the front of the vehicle.

imagePoint2 = [120 400];
annotatedBEV = insertMarker(BEV,imagePoint2);

vehiclePoint = imageToVehicle(birdsEye,imagePoint2);
xAhead = vehiclePoint(1);
displayText = sprintf('%.2f meters',xAhead);
annotatedBEV = insertText(annotatedBEV,imagePoint2 + 5,displayText);

figure
imshow(annotatedBEV)
title('Bird''s-Eye-View Image: imageToVehicle')

More About

expand all

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2017a