Skip to content

pupil labs code

Leon Cheung edited this page Mar 11, 2017 · 13 revisions

pupil labs code

good guide to zmq http://zguide.zeromq.org/page:all#Getting-the-Message-Out

IPC urls

print(ipc_pub_url)                                                          
print(ipc_sub_url)                                                          
print(ipc_push_url)                                                         

# urls change everytime.
tcp://127.0.0.1:39545
tcp://127.0.0.1:40711
tcp://127.0.0.1:35291

These IPC urls are created from zmq.Context()

main() publishes on ipc_sub_url, subscribes on ipc_pub_url, and pulls on ipc_push_url. Therefore their naming convention is from the perspective of the client processes (the publishers), not the server (the intermediary). Therefore we should subscribe to ipc_sub_url.

eye.py

reference https://github.com/pupil-labs/pupil/blob/master/pupil_src/capture/eye.py#L44

comments

pupil_socket = zmq_tools.Msg_Streamer(zmq_ctx, ipc_pub_url)

 """reads eye video and detects the pupil.
    Creates a window, gl context.
    Grabs images from a capture.
    Streams Pupil coordinates.
    Reacts to notifications:
       ``set_detection_mapping_mode``: Sets detection method
       ``eye_process.should_stop``: Stops the eye process
       ``recording.started``: Starts recording eye video
       ``recording.stopped``: Stops recording eye video
       ``frame_publishing.started``: Starts frame publishing
       ``frame_publishing.stopped``: Stops frame publishing
    Emits notifications:
        ``eye_process.started``: Eye process started
        ``eye_process.stopped``: Eye process stopped
    Emits data:
        ``pupil.<eye id>``: Pupil data for eye with id ``<eye id>``
        ``frame.eye.<eye id>``: Eye frames with id ``<eye id>``
    """

notifications

emitted with self.ipc_socket.notify({'subject': 'eye_process.started', 'eye_id': self.eye_id}) self.ipc_socket comes from ipc_socket = zmq_tools.Msg_Dispatcher(zmq_ctx, ipc_push_url)

data

emitted with

pupil_socket.send('frame.eye.%s'%eye_id,{
                        'width': frame.width,
                        'height': frame.width,
                        'index': frame.index,
                        'timestamp': frame.timestamp,
                        'format': frame_publish_format,
                        '__raw_data__': [data]
})

where it comes from pupil_socket = zmq_tools.Msg_Streamer(zmq_ctx, ipc_pub_url)

sample data
pupil.0 {'topic': 'pupil', 'confidence': 0.855533022918575, 'ellipse': {'center': (492.95520782470703, 192.46016693115234), 'axes': (88.91585540771484, 102.81527709960938), 'angle': 140.26339721679688}, 'diameter': 102.81527709960938, 'norm_pos': (0.7702425122261047, 0.5990413188934326), 'timestamp': 14312.967009596, 'method': '2d c++', 'id': 0}
pupil.0 {'topic': 'pupil', 'confidence': 0.844245287361561, 'ellipse': {'center': (492.7257766723633, 192.63697814941406), 'axes': (89.68899536132812, 102.3887939453125), 'angle': 141.23370361328128}, 'diameter': 102.3887939453125, 'norm_pos': (0.7698840260505676, 0.5986729621887207), 'timestamp': 14312.999003514, 'method': '2d c++', 'id': 0}
pupil.0 {'topic': 'pupil', 'confidence': 0.8932404919338338, 'ellipse': {'center': (492.34053802490234, 192.73290252685547), 'axes': (89.91947937011719, 102.31194305419922), 'angle': 142.77885437011722}, 'diameter': 102.31194305419922, 'norm_pos': (0.76928209066391, 0.5984731197357178), 'timestamp': 14313.035021806, 'method': '2d c++', 'id': 0}
pupil.0 {'topic': 'pupil', 'confidence': 0.8921706622563372, 'ellipse': {'center': (491.8279724121094, 192.77881622314453), 'axes': (89.3835220336914, 102.34571838378906), 'angle': 140.5278472900391}, 'diameter': 102.34571838378906, 'norm_pos': (0.7684812068939209, 0.5983774662017822), 'timestamp': 14313.067018182, 'method': '2d c++', 'id': 0}
sample pull from socket
b'pupil.0'
b'\x88\xa5topic\xa5pupil\xaaconfidence\xcb?\xf0\x00\x00\x00\x00\x00\x00\xa7ellipse\x83\xa6center\x92\xcb@~4Z`\x00\x00\x00\xcb@n\x84y\xe0\x00\x00\x00\xa4axes\x92\xcb@;\xbe\x91\xa0\x00\x00\x00\xcb@Hwt\x80\x00\x00\x00\xa5angle\xcb@T\xad\x94\xc0\x00\x00\x00\xa8diameter\xcb@Hwt\x80\x00\x00\x00\xa8norm_pos\x92\xcb?\xe8)\xe1\xe6fff\xcb?\xdfr\xb13334\xa9timestamp\xcb@\xd1\x13\x12w\x7f\x8b\xda\xa6method\xa62d c++\xa2id\x00'
b'pupil.0'
b'\x88\xa5topic\xa5pupil\xaaconfidence\xcb?\xee\xddZ\xeft({\xa7ellipse\x83\xa6center\x92\xcb@~/\xe4\xa0\x00\x00\x00\xcb@n\x7fa\x00\x00\x00\x00\xa4axes\x92\xcb@;\xb3\x16`\x00\x00\x00\xcb@H\xf46 \x00\x00\x00\xa5angle\xcb@U\x16B\x00\x00\x00\x00\xa8diameter\xcb@H\xf46 \x00\x00\x00\xa8norm_pos\x92\xcb?\xe8&P\x80\x00\x00\x00\xcb?\xdfx!\x11\x11\x11\x12\xa9timestamp\xcb@\xd1\x13\x14\x83\xd2\xb9\\\xa6method\xa62d c++\xa2id\x00'
b'pupil.0'
b'\x88\xa5topic\xa5pupil\xaaconfidence\xcb?\xf0\x00\x00\x00\x00\x00\x00\xa7ellipse\x83\xa6center\x92\xcb@~0c\xe0\x00\x00\x00\xcb@n~\xbb\xc0\x00\x00\x00\xa4axes\x92\xcb@;\xb0(\x80\x00\x00\x00\xcb@Hl0 \x00\x00\x00\xa5angle\xcb@U#@ \x00\x00\x00\xa8diameter\xcb@Hl0 \x00\x00\x00\xa8norm_pos\x92\xcb?\xe8&\xb6L\xcc\xcc\xcd\xcb?\xdfx\xd1UUUV\xa9timestamp\xcb@\xd1\x13\x16\xd1mZ\xf7\xa6method\xa62d c++\xa2id\x00'
decoding

have problems with decoding the string starting with \x88, as \x88 is not a valid start character. update: payload is a msgpack serialized string. https://github.com/pupil-labs/pupil/blob/master/pupil_src/shared_modules/zmq_tools.py#L114

fixed here: https://github.com/fsxfreak/esys-pbi/blob/b1fd199564a962e3b3baa76925c35082f0977fe4/src/pupil/listen.py#L25

detector algorithm

see here https://github.com/pupil-labs/pupil/blob/master/pupil_src/capture/pupil_detectors/detect_2d.hpp#L74