This page introduces UnrealCV commands and how to use them to perform basic tasks. We also show how to use a python script to control an UnrealCV embedded game through these commands.
Download a game binary¶
This tutorial will use a game binary to demonstrate UnrealCV commands. You can also create your own game using UnrealCV plugin.
First you need to download a game binary from our model zoo. For this tutorial, please download RealisticRendering. After unzip and run the binary, you are expected to see a screen like this. The game will be started in a window mode with resolution 640x480, you can change the resolution by changing the configuration file of UnrealCV.
Use mouse to look around and use keys
w a s d to navigate, use
q e to level the camera up and down. If you want to release mouse cursor from the game, press ` (the key on top of tab).
UnrealCV provides a set of commands for computer vision research. These commands are used to perform various tasks, such as control camera and get ground truth. The table below summaries commands used in this tutorial. The complete list can be found in the command list in the reference section.
|vset /viewmode [viewmode_name]||Set ViewMode to (lit, normal, depth, object_mask)|
|vget /camera/0/lit||Save image to disk and return filename|
|vset /camera/0/location [x] [y] [z]||Set camera location|
Try UnrealCV commands¶
Unreal Engine provides a built-in console to help developers to debug games. This built-in console is a convenient way of trying UnrealCV commands. To open the console, press `
(the key on top of tab) twice, a console will pop out, as shown in Fig. 2. Type in
vset /viewmode object_mask you are expected to see the object instance mask. Use
vset /viewmode lit to switch back to normal rendering setting.
Use python client to execute commands¶
If we want to generate a large-scale synthetic dataset, or do active tasks, such as reinforcement learning, in this virtual world. We need to allow an intelligent agent to perceive, navigate and interact in the scene. We provide UnrealCV client to enable other programs to communicate with this virtual world. The client will use a plain-text protocol to exchange information with the game.
Here we use the python client for illustration. If you are looking for a MATLAB client, please see the MATLAB client.
First, we need to install the python client library.
Install UnrealCV python library¶
pip install unrealcv
Generate some images from the scene¶
from unrealcv import client client.connect() # Connect to the game if not client.isconnected(): # Check if the connection is successfully established print 'UnrealCV server is not running. Run the game from http://unrealcv.github.io first.' else: filename = client.request('vget /camera/0/lit') filename = client.request('vget /camera/0/depth depth.exr')
You can find this example in examples/10lines.py.
If you encountered any errors following this tutorial, please see the diagnosis page to find a solution.
Next: Use UnrealCV in the game mode or plugin mode?¶
For the game mode, you can use a compiled game binary. You can freely control the camera in this game and generate images and ground truth from it. But it is not easy to change the scene, such as add more objects or change the material properties. If you have access to an UE4 project and know how to use the UE4Editor, you can install the plugin to UE4Editor, so that you can combine the power of UE4Editor and UnrealCV to create new virtual worlds for research.