UnrealCV Commands Demo


In [1]:
from unrealcv.automation import UE4Binary
from unrealcv.util import read_png, read_npy
from unrealcv import client

In [2]:
import matplotlib.pyplot as plt
plt.ion()
%matplotlib inline

In [3]:
import os
binary_path = '../Binaries/RealisticRendering/WindowsNoEditor/RealisticRendering.exe'
if os.path.isfile(binary_path):
    # Use .exe file for windows.
    binary = UE4Binary(binary_path) # UE4Binary can support exe, linux and mac binary
    binary.start()
else:
    print("Can not find binary file %s \nWorking directory is %s" % (binary_path, os.path.abspath('.')))

def show_current_frame():
    res = client.request('vget /camera/0/lit png'); img = read_png(res); plt.imshow(img)


Can not find binary file ../Binaries/RealisticRendering/WindowsNoEditor/RealisticRendering.exe 
Working directory is /Users/qiuwch/unrealcv/examples

In [5]:
client.connect()
print(client.request('vget /unrealcv/version'))
print(client.request('vget /unrealcv/status'))


INFO:__init__:211:Got connection confirm: 'connected to RealisticRendering'
0.3.10
Is Listening
Client Connected
9000
Configuration
Config file: /Users/qiuwch/unrealcv/UE4Binaries/RealisticRendering/MacNoEditor/RealisticRendering.app/Contents/UE4/Engine/Binaries/Mac/unrealcv.ini
Port: 9000
Width: 640
Height: 480
FOV: 90.000000
EnableInput: true
EnableRightEye: false

Camera operation


In [6]:
res = client.request('vget /camera/0/lit png')
img = read_png(res)
plt.imshow(img)


Out[6]:
<matplotlib.image.AxesImage at 0x10d1a5a90>

In [7]:
res = client.request('vget /camera/0/location')
print(res)
res = client.request('vget /camera/0/rotation')
print(res)


-106.195 437.424 91.141
0.001 -92.000 0.000

In [8]:
res = client.request('vset /camera/0/location -162 -126 90')
print(res)
res = client.request('vset /camera/0/rotation 348 60 0')
print(res)


ok
ok

In [9]:
res = client.request('vget /camera/0/lit png')
img = read_png(res)
res = client.request('vget /camera/0/depth npy')
depth = read_npy(res)
res = client.request('vget /camera/0/normal png')
normal = read_png(res)
res = client.request('vget /camera/0/object_mask png')
object_mask = read_png(res)
fig = plt.figure(figsize = (10, 10))
plt.subplot(221); plt.imshow(img); plt.title("Image")
plt.subplot(222); plt.imshow(depth); plt.title("Depth")
plt.subplot(223); plt.imshow(normal); plt.title("Surface Normal")
plt.subplot(224); plt.imshow(object_mask)


Out[9]:
<matplotlib.image.AxesImage at 0x10d902b90>

In [10]:
res = client.request('vget /camera/0/lit lit.png')
print(res)
res = client.request('vget /camera/0/depth depth.png')
print(res)
res = client.request('vget /camera/0/object_mask object_mask.png')
print(res)


/Users/qiuwch/unrealcv/UE4Binaries/RealisticRendering/MacNoEditor/RealisticRendering.app/Contents/UE4/Engine/Binaries/Mac/lit.png
/Users/qiuwch/unrealcv/UE4Binaries/RealisticRendering/MacNoEditor/RealisticRendering.app/Contents/UE4/Engine/Binaries/Mac/depth.png
/Users/qiuwch/unrealcv/UE4Binaries/RealisticRendering/MacNoEditor/RealisticRendering.app/Contents/UE4/Engine/Binaries/Mac/object_mask.png

In [11]:
res = client.request('vget /camera/0/pose')
# (v0.3.10) Get camera location [x, y, z] and rotation [pitch, yaw, roll]
print(res)
res = client.request('vset /camera/0/pose -162 -126 90 348 60 0')
# (v0.3.10) Teleport camera to location [x, y, z] and rotation [pitch, yaw, roll]
print(res)


-162.000 -126.000 91.140 348.000 60.000 0.000
ok

In [12]:
res = client.request('vget /camera/0/horizontal_fieldofview')
# (v0.3.10) Teleport camera to location [x, y, z] and rotation [pitch, yaw, roll]
print(res)
res = client.request('vset /camera/0/horizontal_fieldofview 140')
# (v0.3.10) Set camera horizontal field of view
show_current_frame()
res = client.request('vset /camera/0/horizontal_fieldofview 90') # reset for next commands


90.000

Object Interaction


In [13]:
res = client.request('vget /objects')
object_names = res.split(' ')
print(object_names[:5])


[u'Carpet_5', u'SM_CoffeeTable_14', u'Couch_13', u'SM_Room_7', u'SM_Room_OuterShell_14']

In [14]:
res = client.request('vget /object/Couch_13/color')
print(res)


(R=0,G=255,B=0,A=255)

In [15]:
res = client.request('vget /object/Couch_13/location')
print(res)
res = client.request('vget /object/Couch_13/rotation')
print(res)


185.00 -5.00 0.00
0.00 2.23 0.00

In [16]:
res = client.request('vset /object/Couch_13/hide')
# (v0.3.10) Hide object
plt.subplot(121); plt.title('hide Couch_13')
show_current_frame()

res = client.request('vset /object/Couch_13/show') # reset for next commands
plt.subplot(122); plt.title('show Couch_13')
show_current_frame()

# (v0.3.10) Show object



In [29]:
res = client.request('vget /object/Couch_13/location')
print(res)
res = client.request('vget /object/Couch_13/rotation')
print(res)
res = client.request('vget /object/Couch_13/mobility')
print(res)
res = client.request('vset /object/Couch_13/location 185.00 -5.00 40.00')
print(res) # In the RR envrionment, we don't have a good object to demo this command
res = client.request('vset /object/Couch_13/rotation 0 0 0')
print(res)
show_current_frame()


185.00 -5.00 0.00
0.00 2.23 0.00
Static
error Failed to move object Couch_13
ok

Action Command


In [32]:
res = client.request('vset /action/keyboard w 3') # Use keyboard to move forward
show_current_frame()
print(res)


ok

In [17]:
res = client.request('vset /action/game/level RoomNight')
print(res)
# (v0.3.10) Open a new level


ok

In [18]:
show_current_frame()


Call blueprint functions


In [19]:
client.request('vrun /') # WIP


Out[19]:
u'ok'

Plugin Commands


In [20]:
res = client.request('vget /unrealcv/status')
print(res)


Is Listening
Client Connected
9000
Configuration
Config file: D:/pull_request_merge/UE4RealisticRendering/Plugins/unrealcv/Binaries/RealisticRendering/WindowsNoEditor/RealisticRendering/Binaries/Win64/unrealcv.ini
Port: 9000
Width: 640
Height: 480
FOV: 90.000000
EnableInput: true
EnableRightEye: false


In [21]:
res = client.request('vget /unrealcv/version')
print(res)


0.3.10

In [22]:
binary.close()


Kill windows binary with command ['taskkill', '/F', '/IM', 'RealisticRendering.exe']