Python API

class unrealcv.Client(endpoint, type='inet')

Client can be used to send request to a game and get response Currently only one client is allowed at a time More clients will be rejected

connect(timeout=1)

Try to connect to server, return whether connection successful

receive()

Receive packages, Extract message from packages Call self.message_handler if got a message Also check whether client is still connected

request(message, timeout=5)

Send a request to server and wait util get a response from server or timeout.

Parameters
Returns

plain text message from server

Return type

str

Examples

>>> client = Client('localhost', 9000)
>>> client.connect()
>>> response = client.request('vget /camera/0/view')
request_async(message)

Send request without waiting for any reply

send(message)

Send message out, return whether the message was successfully sent

Some useful utility functions for reading data

unrealcv.util.read_png(res)

Return a numpy array from binary bytes of png format

Parameters

res (bytes) – For example, res = client.request(‘vget /camera/0/lit png’)

Returns

Numpy array

Return type

numpy.array

unrealcv.util.read_npy(res)

Return a numpy array from binary bytes of numpy binary file format

Parameters

res (bytes) – For example, res = client.request(‘vget /camera/0/depth npy’)

Returns

Numpy array

Return type

numpy.array

The unrealcv.automation module to help building the plugin, packaging model zoo binaries, etc.

unrealcv.automation.UE4Binary(binary_path)

Return a platform-dependent binary for user.

Examples

>>> binary = UE4Binary('./WindowsNoEditor/RealisticRendering.exe')  # For windows
>>> binary = UE4Binary('./LinuxNoEditor/RealisticRendering/Binaries/RealisticRendering') # For Linux
>>> binary = UE4Binary('./MacNoEditor/RealisticRendering.app') # For mac
>>> with binary: # Automatically launch and close the binary
>>>     client.request('vget /unrealcv/status')
>>> # Or alternatively
>>> binary.start()
>>> client.request('vget /unrealcv/status')
>>> binary.close()
class unrealcv.automation.UE4Automation(engine)

UE4 engine wrapper

build_plugin(plugin_descriptor, output_folder, overwrite=False)

Use RunUAT script to build the plugin

Parameters
  • plugin_descriptor (str) –

  • output_folder (str) –

  • overwrite (bool) – Whether the compiled binary folder should be overwriten?

install(plugin_folder, overwrite=False)

Install the plugin to UE4 engine folder

Parameters

plugin_folder (str) – The plugin folder with compiled binaries

package(project_descriptor, output_folder, overwrite=False)

Package an UE4 project

Parameters
  • project_descriptor (str) – UE4 project file name ends with *.uproject

  • overwrite (bool) – Overwrite existing files