forked from PoseAI/PoseCameraAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_python.py
More file actions
64 lines (50 loc) · 1.88 KB
/
demo_python.py
File metadata and controls
64 lines (50 loc) · 1.88 KB
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
'''
Authored by Pose AI Ltd, 2021
Simple demo of a UDP server for Pose Camera in python.
Once connected will receive stream of poses from the app
Apache License 2.0
'''
import socket
import json
PORT_NUM = 8080
''' Prints your local IP address. Configure this in the App.
Make sure your router and firewall do not block the port '''
def show_my_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(('10.255.255.255', 1))
ip = s.getsockname()[0]
except Exception:
ip = '127.0.0.1'
finally:
s.close()
print("Connect the app to IP:", ip, "Port:", PORT_NUM)
# The handshake configures the app
handshake = json.dumps(
{
'HANDSHAKE': {
'name': 'PythonDemo', # will be displayed in the app
'rig': 'UE4', # Options: 'UE4', 'Mixamo'
'mode': 'Desktop', # Options: 'Room', 'Desktop', 'Portrait', 'RoomBodyOnly', 'PortraitBodyOnly'
'mirror': 'YES', # Options: 'YES', 'NO'
'syncFPS': 60, # App smooths processed frames to constant FPS. 0 for async mode (will still smooth joints between processed frames)
'cameraFPS': 60, # Tries to set camera to this speed. 30 and 60 work on most iphone cameras
}
}
).encode()
show_my_ip()
connections = {}
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('0.0.0.0', PORT_NUM))
while True:
message, address = server_socket.recvfrom(65304)
message = message.decode('utf-8')
decoded_message = json.loads(message)
if 'sessionUUID' in decoded_message.keys():
# is initial connection, send it the handshake
print(decoded_message, address)
connections[decoded_message['sessionUUID']] = address
server_socket.sendto(handshake, address)
else:
# message holds pose data, do what you want with it
print(decoded_message)