-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_positions.py
77 lines (62 loc) · 2.24 KB
/
example_positions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# Copyright (C) 2020 Enrico Meloni, Luca Pasqualini, Matteo Tiezzi
# University of Siena - Artificial Intelligence Laboratory - SAILab
#
#
# SAILenv is licensed under a MIT license.
#
# You should have received a copy of the license along with this
# work. If not, see <https://en.wikipedia.org/wiki/MIT_License>.
# Import packages
import random
import cv2
# Import src
from sailenv.agent import Agent
host = "127.0.0.1"
if __name__ == '__main__':
print("Generating agent...")
agent = Agent(depth_frame_active=False,
flow_frame_active=False,
object_frame_active=False,
main_frame_active=True,
category_frame_active=False, width=256, height=192, host=host, port=8085, use_gzip=False)
print("Registering agent on server...")
agent.register()
print(f"Agent registered with ID: {agent.id}")
last_unity_time: float = 0.0
print(f"Available scenes: {agent.scenes}")
scene = agent.scenes[1]
print(f"Changing scene to {scene}")
agent.change_scene(scene)
agent.get_categories()
print(f"Available categories: {agent.categories}")
try:
print("Press ESC to close")
frame_n = 1
while True:
print(f"Frame: {frame_n}")
if frame_n % 3 == 0:
print("Random change")
x = random.uniform(-1., 1.)
y = random.uniform(0.5, 1.5)
z = random.uniform(-1., 1.)
rx = random.uniform(0., 360.)
ry = random.uniform(0., 360.)
rz = random.uniform(0., 360.)
agent.set_position((x, y, z))
agent.set_rotation((rx, ry, rz))
print("Position: " + str(agent.get_position()))
print("Rotation: " + str(agent.get_rotation()))
print("")
frame = agent.get_frame()
if frame["main"] is not None:
main_img = frame["main"]
cv2.imshow("PBR", main_img)
key = cv2.waitKey(1000)
# print(f"FPS: {1/(time.time() - start_real_time)}")
if key == 27: # ESC Pressed
break
frame_n += 1
finally:
print(f"Closing agent {agent.id}")
agent.delete()