Create Top-Down Static Map of Unreal Engine Scene
Because 3-D scenes developed for the Unreal Engine® simulation environment are large and complex, it can be difficult to use them to test automated driving algorithms. To simplify testing algorithms or get a big-picture view of your scene, you can use the Unreal® Editor to create a 2-D, top-down map of a scene or a subsection of a scene. This example shows you how to create a top-down map of an area from an Unreal Engine scene by using the Unreal Editor.
Set Up Camera and Take Screenshot in Unreal Editor
You can capture the entire scene or a specific rectangular area of interest, by placing a camera actor in the Unreal Editor and using the camera view for the screenshot. You need to know the X-axis and Y-axis limits of the area so you can then convert the screenshot into a map. You can determine the size of the area by setting up an Unreal Editor Camera Actor that looks at a view from your scene to capture the dimensions of a known area of interest.
For this example, take a top-down screenshot of the Large Parking Lot scene, in the area outlined in blue in this image.The area is a 70-by-45 meter rectangle offset from the scene origin by –40 meter on the X-axis and 15 meter on the Y-axis.
Open the Unreal Editor from a Simulink model that is configured with the Unreal Editor. For more details, see Customize Scenes Using Simulink and Unreal Editor.
Open your scene in the Unreal Editor.
Click in the Unreal Editor Viewport and press G to enter Game View. This view shows the scene as it appears in a simulation, without editor-specific elements.
Place your Camera Actor into the Unreal Editor scene. You can do this by searching for a Camera and then dragging the actor into the scene.
5. To configure the camera for viewing the correct area of the scene specify these Camera Settings
Projection Mode —
Aspect Ratio —
Ortho Width —
6. To move the camera into position, specify these settings for the Camera Actor Location. The X and Y values specify the coordinate center of your area of interest in the corresponding dimension, in centimeters. The Z value should be placed any high distance to be above all objects in your scene.
7. To orient the camera in the correct direction specify these settings for the Camera Actor Rotation. Each value specifies the angle of the camera relative to the corresponding axis, in degrees.
8. Switch to the camera view of the scene. In the top-left corner of the editing window, click Perspective, and then, under Placed Cameras, select your camera.
9. To verify that the scene is lit by standard lighting, in the top-left corner of the editing window, click the View Mode menu and check that Lit is selected.
10. Take a screenshot, which acts as a 2-D scene map. In the top-left corner of the editing window, click the down arrow and select High Resolution Screenshot. To increase the quality of the image, increase the value of Screenshot Size Multiplier to 3. Then, click Take a screenshot.
The Unreal Editor displays a message that indicates the path of the saved screenshot. By default, the Unreal Editor saves the screenshot to a folder in your project based on your operating system. For example, on Windows, this is the default path:
where myProject is the path to the folder for your current project. You can access the image file by clicking the path in the message.
Convert Screenshot to Map
After you create your high-resolution screenshot, you can convert it to a map by creating a 2-D spatial referencing object,
imref2d. This object describes the relationship between the pixels in the image and the world coordinates of the scene.
sceneImage = imread("myScene.png"); imageSize = size(sceneImage); xlims = [-40 30]; % in meters ylims = [15 60]; % in meters sceneRef = imref2d(imageSize,xlims,ylims); imshow(flip(sceneImage,1), sceneRef) % Display and flip the image to keep correct image orientation after the next step set(gca,YDir="normal",Visible="on") % Correct Y axis for right-handed world Cartesian coordinate system xlabel("X (m)") ylabel("Y (m)")
You can use the scene image and spatial referencing object to select waypoints for vehicles to follow in your scene. For more information, see the Select Waypoints for Unreal Engine Simulation example.