由alea技术开发的intelligaze api的python包装器
python-alea的Python项目详细描述
皮亚利亚
intelligaze api的python包装器由Alea Technologies。
C API
alea提供了一个api来与眼睛跟踪器交互。这个api通过com操作,用python包装起来不那么简单。(在技术上可能的情况下,它需要外部包,并跳过几个环。)一个更简单的解决方案是为API引入一个C++包装器,然后将其编译成一个DLL。生成的dll更容易通过python的ctypes
访问。
原始api的这个“c api”包装器的源代码包含在这里。
下载并安装
pyalea可以通过python包索引(pypi)获得,并且可以通过pip
安装。
pip install python-alea
用法
安装后,可以将alea包导入到python脚本中:
import alea
将数据记录到文件中
然后,您可以使用aleatracker类来快速方便地与您的眼睛跟踪器交互。例如,以下脚本初始化与intelligaze服务器的连接,校准眼睛跟踪器,并将10秒的数据记录到文本文件中。
import time
from alea import AleaTracker
# Initialise the connection to the IntelliGaze Server,
# using the PyGaze alea code.
tracker = AleaTracker("pg=12", file_path="my_data.tsv")
# Calibrate the eye tracker, using the default options.
tracker.calibrate()
# Start recording to file.
tracker.start_recording()
# Log a message to the data file.
tracker.log("recording_started")
# Wait for 10 seconds.
time.sleep(10.0)
# Stop recording.
tracker.stop_recording()
# Close the connection to the eye tracker.
tracker.close()
凝视相关功能的流式采样
你可以使用aleatracker的sample
方法来获得相应的凝视坐标,以及当前的瞳孔大小。当连接打开时,这将始终返回最新的可用示例。
注意:使用sample
方法不需要录制,使用sample
方法不影响录制。您可以同时执行这两项操作,但不必执行。
import time
from alea import AleaTracker
# Initialise the connection to the IntelliGaze Server,
# using the PyGaze alea code.
tracker = AleaTracker("pg=12", file_path="my_data.tsv")
# Calibrate the eye tracker, using the default options.
tracker.calibrate()
# Run for 10 seconds.
t0 = time.time()
while time.time() - t0 < 10.0:
# Get the latest sample
time_stamp, gaze_x, gaze_y, pupil_size = tracker.sample()
# Print the current sample to the terminal.
print("t=%.3f, x=%.2f, y=%.2f, s=%.2f" % (time_stamp, gaze_x, gaze_y, pupil_size))
# Wait for 33 milliseconds.
time.sleep(0.033)
# Close the connection to the eye tracker.
tracker.close()
故障排除
- 确保Intelligaze服务器正在运行!如果没有它,python包装器就没有什么可谈的了。
- 请确保安装Intelligaze服务器!你可以通过Alea Technologies website从intelligaze下载它。
- 请确保运行的是Microsoft Windows操作系统(在Windows 7和10上进行了测试)。Linux和OS X支持目前不可用。