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)
In [5]:
client.connect()
print(client.request('vget /unrealcv/version'))
print(client.request('vget /unrealcv/status'))
In [6]:
res = client.request('vget /camera/0/lit png')
img = read_png(res)
plt.imshow(img)
Out[6]:
In [7]:
res = client.request('vget /camera/0/location')
print(res)
res = client.request('vget /camera/0/rotation')
print(res)
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)
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]:
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)
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)
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
In [13]:
res = client.request('vget /objects')
object_names = res.split(' ')
print(object_names[:5])
In [14]:
res = client.request('vget /object/Couch_13/color')
print(res)
In [15]:
res = client.request('vget /object/Couch_13/location')
print(res)
res = client.request('vget /object/Couch_13/rotation')
print(res)
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()
In [32]:
res = client.request('vset /action/keyboard w 3') # Use keyboard to move forward
show_current_frame()
print(res)
In [17]:
res = client.request('vset /action/game/level RoomNight')
print(res)
# (v0.3.10) Open a new level
In [18]:
show_current_frame()
In [19]:
client.request('vrun /') # WIP
Out[19]:
In [20]:
res = client.request('vget /unrealcv/status')
print(res)
In [21]:
res = client.request('vget /unrealcv/version')
print(res)
In [22]:
binary.close()