【发布时间】:2018-12-10 09:23:44
【问题描述】:
from pymouse.windows import PyMouse
import zmq
#from pymouse import PyMouse
#mouse setup
m = PyMouse()
x_dim, y_dim = m.screen_size()
#network setup
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://127.0.0.1:5000")
#filter by messages by stating string 'STRING'. '' receives all messages
socket.setsockopt(zmq.SUBSCRIBE, '')
smooth_x, smooth_y= 0.5, 0.5
while True:
msg = socket.recv()
items = msg.split("\n")
msg_type = items.pop(0)
items = dict([i.split(':') for i in items[:-1] ])
if msg_type == 'Pupil':
try:
my_gaze = items['norm_gaze']
if my_gaze != "None":
raw_x,raw_y = map(float,my_gaze[1:-1].split(','))
# smoothing out the gaze so the mouse has smoother movement
smooth_x += 0.5 * (raw_x-smooth_x)
smooth_y += 0.5 * (raw_y-smooth_y)
x = smooth_x
y = smooth_y
y = 1-y # inverting y so it shows up correctly on screen
x *= x_dim
y *= y_dim
x = min(x_dim-10, max(10,x))
y = min(y_dim-10, max(10,y))
m.move(x,y)
except KeyError:
pass
else:
# process non gaze position events from plugins here
pass`
在这里运行此代码时出现错误:
runfile('C:/Users/Richa Agrawal/Downloads/Compressed/Computer_Vision_A_Z_Template_Folder/Code_for_Windows/Code for Windows/what.py', wdir='C:/Users/Richa Agrawal/Downloads/Compressed/Computer_Vision_A_Z_Template_Folder/Code_for_Windows/ Windows 代码') Traceback(最近一次调用最后一次):
文件“”,第 1 行,在 runfile('C:/Users/Richa Agrawal/Downloads/Compressed/Computer_Vision_A_Z_Template_Folder/Code_for_Windows/Code for Windows/what.py', wdir='C:/Users/Richa Agrawal/Downloads/Compressed/Computer_Vision_A_Z_Template_Folder/Code_for_Windows/Windows 代码')
文件“C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 880 行,在运行文件中 execfile(文件名,命名空间)
文件“C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”,第 102 行,在 execfile exec(编译(f.read(),文件名,'exec'),命名空间)
文件“C:/Users/Richa Agrawal/Downloads/Compressed/Computer_Vision_A_Z_Template_Folder/Code_for_Windows/Code for Windows/what.py”,第 20 行,在 socket.setsockopt(zmq.SUBSCRIBE, '')
文件“zmq/backend/cython/socket.pyx”,第 374 行,在 zmq.backend.cython.socket.Socket.set (zmq\backend\cython\socket.c:4610)中
TypeError: unicode not allowed,使用 setsockopt_string
【问题讨论】:
标签: python zeromq eye-tracking