Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Pupil Capture v1.21 #39

Merged
merged 4 commits into from Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/filter_gaze_on_surface.py
Expand Up @@ -32,7 +32,7 @@
filtered_surface = {k: v for k, v in surfaces.items() if surfaces['name'] == surface_name}
try:
# note that we may have more than one gaze position data point (this is expected behavior)
gaze_positions = filtered_surface['gaze_on_srf']
gaze_positions = filtered_surface['gaze_on_surfaces']
for gaze_pos in gaze_positions:
norm_gp_x, norm_gp_y = gaze_pos['norm_pos']

Expand Down
1 change: 1 addition & 0 deletions python/pupil_remote_control.py
Expand Up @@ -63,4 +63,5 @@ def notify(notification):

#test notification, note that you need to listen on the IPC to receive notifications!
notify({'subject':"calibration.should_start"})
sleep(5)
notify({'subject':"calibration.should_stop"})
3 changes: 1 addition & 2 deletions python/recv_world_video_frames.py
Expand Up @@ -5,7 +5,6 @@
import zmq
from msgpack import unpackb, packb
import numpy as np
import cv2

context = zmq.Context()
# open a req port to talk to pupil
Expand Down Expand Up @@ -73,4 +72,4 @@ def recv_from_sub():
recent_eye1 = np.frombuffer(msg['__raw_data__'][0], dtype=np.uint8).reshape(msg['height'], msg['width'], 3)

if recent_world is not None and recent_eye0 is not None and recent_eye1 is not None:
pass # here you can do calculation on the 3 most recent world, eye0 and ey1 images
print(f"here you can do calculation on the 3 most recent world, eye0 and eye1 images... latest message was {topic}")
85 changes: 85 additions & 0 deletions python/recv_world_video_frames_with_visualization.py
@@ -0,0 +1,85 @@
"""
Receive world camera data from Pupil using ZMQ.
Make sure the frame publisher plugin is loaded and confugured to gray or rgb
"""
import zmq
from msgpack import unpackb, packb
import numpy as np
import cv2

context = zmq.Context()
# open a req port to talk to pupil
addr = '127.0.0.1' # remote ip or localhost
req_port = "50020" # same as in the pupil remote gui
req = context.socket(zmq.REQ)
req.connect("tcp://{}:{}".format(addr, req_port))
# ask for the sub port
req.send_string('SUB_PORT')
sub_port = req.recv_string()


# send notification:
def notify(notification):
"""Sends ``notification`` to Pupil Remote"""
topic = 'notify.' + notification['subject']
payload = packb(notification, use_bin_type=True)
req.send_string(topic, flags=zmq.SNDMORE)
req.send(payload)
return req.recv_string()


# Start frame publisher with format BGR
notify({'subject': 'start_plugin', 'name': 'Frame_Publisher', 'args': {'format': 'bgr'}})

# open a sub port to listen to pupil
sub = context.socket(zmq.SUB)
sub.connect("tcp://{}:{}".format(addr, sub_port))

# set subscriptions to topics
# recv just pupil/gaze/notifications
sub.setsockopt_string(zmq.SUBSCRIBE, 'frame.')


def recv_from_sub():
'''Recv a message with topic, payload.

Topic is a utf-8 encoded string. Returned as unicode object.
Payload is a msgpack serialized dict. Returned as a python dict.

Any addional message frames will be added as a list
in the payload dict with key: '__raw_data__' .
'''
topic = sub.recv_string()
payload = unpackb(sub.recv(), encoding='utf-8')
extra_frames = []
while sub.get(zmq.RCVMORE):
extra_frames.append(sub.recv())
if extra_frames:
payload['__raw_data__'] = extra_frames
return topic, payload


recent_world = None
recent_eye0 = None
recent_eye1 = None

try:
while True:
topic, msg = recv_from_sub()
if topic == 'frame.world':
recent_world = np.frombuffer(msg['__raw_data__'][0], dtype=np.uint8).reshape(msg['height'], msg['width'], 3)
elif topic == 'frame.eye.0':
recent_eye0 = np.frombuffer(msg['__raw_data__'][0], dtype=np.uint8).reshape(msg['height'], msg['width'], 3)
elif topic == 'frame.eye.1':
recent_eye1 = np.frombuffer(msg['__raw_data__'][0], dtype=np.uint8).reshape(msg['height'], msg['width'], 3)

if recent_world is not None and recent_eye0 is not None and recent_eye1 is not None:
cv2.imshow("world", recent_world)
cv2.imshow("eye0", recent_eye0)
cv2.imshow("eye1", recent_eye1)
cv2.waitKey(1)
pass # here you can do calculation on the 3 most recent world, eye0 and eye1 images
except KeyboardInterrupt:
pass
finally:
cv2.destroyAllWindows()