ddetommaso / tobiiglassespycontroller Goto Github PK
View Code? Open in Web Editor NEWTobii Pro Glasses 2 Python controller
License: GNU General Public License v3.0
Tobii Pro Glasses 2 Python controller
License: GNU General Public License v3.0
Hi everyone,
Thanks a lot for this very useful toolbox.
I have come across an issue line 193 that I have corrected, see below. Otherwise, everything is working fine !
Issue :
TypeError: a bytes-like object is required, not 'str'
Correction suggested :
sock.setsockopt(socket.SOL_SOCKET, 25, (self.iface_name+'\0').encode())
The while
loop in wait_for_status
should take a timeout and return or throw an exception after the sleep counter reaches that value, and __init__
should take a timeout param that it passes to __connect__
. Otherwise I have to force-kill it every time I mistype the ip!
Hi !
I made a recording video project using tobii glasses, and created a csv file using Pysuite.
However, the time stamp in the csv file gives an error. If I change the time stamp to an absolute time, it returns to the 1970s.
Could you tell me how to fix this part?
And I have one more question.
When playing tobii live, is there a way to save 'project' to the SD card like when recording tobii? 'Project' is the folder with livedata.json or videos that will be played live.
Hi Davide,
I report you that there is a difference between git and pip version in tobiiglassesctrl/controller.py
In GIT version, the method create-project
requires the value self.participant_name
instead of the param projectname
.
This makes impossible to create the project because in order to assign self.participant_name
you need to call create_participant
that requires project_id
(returned by create_project
).
In PIP (version 2.2.4) instead the function is correct. it uses the param projectname
.
Cheers,
Dario
Hello, I am a college student living in Korea.
First of all, I have Tobii Glass 2. I downloaded the GitHub source code you uploaded and ran live_scene.py, but there was an error, so I'd like to ask you.
I connected the eye tracker to the laptop using Ethernet connection, and I modified IPv6 of the existing code.
If you know what's wrong with running live_scene.py, please answer! Thank you.
Is there any requirement for running live_scene.py?
Hi ddetommaso, thanks for sharing the code to control tobii glasses!
With your code I can stream the gaze data now but I failed to stream the scene camera video.
I got an error in this line of code.
ipv4_address = "192.168.71.50"
cap = cv2.VideoCapture("rtsp://%s/live/scene" % ipv4_address)
Does using ipv4 address here means the code can only work with wifi connection?
Since in streaming code we seem to use ipv6 I . (e.g. fe80::76fe:......)
Thanks!
Hello, the python code can be converted to c++ code easily? C++ code is more convenient because of my needs.
When I was trying to install the TobiiGlassesPyController in python 3.8.5 I got the following errors:
In python 3.6 there was no problem.
Hello, I don't know if you remember, but I'm a Korean university student who used Tobii on ROS last time.
Thank you so much for your help last time.
I have a question, so I'm inquiring like this.
May I know if this source code works for 'Tobii pro glasses3' as well?
Thank you!
Hello, I am a university student living in Korea.
I'm interested in using Tobii glasses' data, so I have a question while I was studying the ROS, so I'm asking this
What I want is to send real-time data from Tobii glasses to subscribers via ROS.
So, I would like to apply rospy to live_scene_and_gaze.py file.
This is the code that I use as a publisher in ROS.
I don't know how to combine this code with the live_scene_and_gaze.py code.
If you have any ideas, I'd appreciate it if you could let me know.
Hi first of all thanks for doing this really great job. I took your streaming example and adapted it to stream the data from the controller to Labstreaminglayer (LSL). Really useful in case you want to record more signals along with the eye tracker.
If this is interesting I could send a pull request so that you have that additional example in your repository
hello, Sir.I am writing to ask you some questions about the project TobiiGlassesPyController you posted on github.We cannot successfully complete the calibration of tobii with the
example live_scene_and_gaze.py, program clocked and no return value as shown in the following figure. Is there anything we should pay attention to?Looking forward to your reply.Thank you very much.
The current class calls quit()
when the connection fails. This works poorly when integrated into other processes that might want to do custom error handling. It would be better to raise an exception (possibly ConnectionError or a custom error), and then the calling application can do better error handling.
This should be a simple change (replace both instances of quit()
with e.g. raise ConnectionError("Failed to connect to Tobii device")
). I can submit a PR if that's useful, assuming you can determine the appropriate exception type.
Hi, this gets a list of all recordings, which I am using to find the most recent one:
def get_recordings(self):
return self.__get_request__('/api/recordings')
Thanks,
Originally posted by @HamAndChris in #5 (comment)
Hello, I have added the following functions to my controller.py which enables changing the default eye tracking frequency:
def get_et_freq(self):
return self.get_configuration()['sys_et_freq']
def get_et_frequencies(self):
return self.get_status()['sys_et']['frequencies']
def set_et_freq_50(self):
data = {'sys_et_freq': 50}
json_data = self.__post_request__('/api/system/conf', data)
def set_et_freq_100(self):
"""May not be available. Check get_et_frequencies() first."""
data = {'sys_et_freq': 100}
json_data = self.__post_request__('/api/system/conf', data)
Also, this allows querying the list of participants and projects directly:
def get_projects(self):
return self.__get_request__('/api/projects')
def get_participants(self):
return self.__get_request__('/api/participants')
I would just make a pull request but I'm too lazy.
Thanks,
Hello, thanks for sharing the codes for controlling tobii glasses!
I am trying to get a map between videos and gaze data online, but I am getting a map with a delayed image and a real-time gaze data.
So I would be happy if you could tell me the way to get an online map between videos and gaze data correctly.
Thanks in advance!
Glasses Firmware Version: 1.25.4-citronkola-0
Headunit version: 0.0.62
Python: Python 3.5.6 :: Anaconda, Inc.
IDE: Jupyter lab with Ipykernel 5.1.0
Copied from demo code:
import time
from tobiiglassesctrl.controller import TobiiGlassesController
if hasattr(__builtins__, 'raw_input'):
input=raw_input
def main():
tobiiglasses = TobiiGlassesController("192.168.71.50")
print(tobiiglasses.get_battery_info())
print(tobiiglasses.get_storage_info())
if tobiiglasses.is_recording():
rec_id = tobiiglasses.get_current_recording_id()
tobiiglasses.stop_recording(rec_id)
project_name = input("Please insert the project's name: ")
project_id = tobiiglasses.create_project(project_name)
participant_name = input("Please insert the participant's name: ")
participant_id = tobiiglasses.create_participant(project_id, participant_name)
calibration_id = tobiiglasses.create_calibration(project_id, participant_id)
input("Put the calibration marker in front of the user, then press enter to calibrate")
tobiiglasses.start_calibration(calibration_id)
res = tobiiglasses.wait_until_calibration_is_done(calibration_id)
if res is False:
print("Calibration failed!")
exit(1)
recording_id = tobiiglasses.create_recording(participant_id)
print("Important! The recording will be stored in the SD folder projects/%s/recordings/%s" % (project_id, recording_id))
input("Press enter to start recording")
tobiiglasses.start_recording(recording_id)
tobiiglasses.send_custom_event("start_recording", "Start of the recording ")
input("Press enter to stop recording")
tobiiglasses.send_custom_event("stop_recording", "Stop of the recording " + str(recording_id))
tobiiglasses.stop_recording(recording_id)
if res is False:
print("Recording failed!")
exit(1)
if __name__ == '__main__':
main()
Error:
[DEBUG]: Connecting to the Tobii Pro Glasses 2 ...
[DEBUG]: Tobii Pro Glasses 2 successful connected!
Battery info = [ Level: 86.00 % - Remaining Time: 5160.00 s ]
Storage info = [ Remaining Time: 5160.00 s ]
Please insert the project's name: Li
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-19-4597c1eb8694> in <module>
44
45 if __name__ == '__main__':
---> 46 main()
<ipython-input-19-4597c1eb8694> in main()
14
15 project_name = input("Please insert the project's name: ")
---> 16 project_id = tobiiglasses.create_project(project_name)
17
18 participant_name = input("Please insert the participant's name: ")
D:\Miniconda3\envs\python35\lib\site-packages\tobiiglassesctrl\controller.py in create_project(self, projectname)
320 if project_id is None:
321 data = {'pr_info' : {'CreationDate': self.__get_current_datetime__(),
--> 322 'EagleId': str(uuid.uuid5(uuid.NAMESPACE_DNS, projectname.encode('utf-8'))),
323 'Name': projectname},
324 'pr_created': self.__get_current_datetime__() }
D:\Miniconda3\envs\python35\lib\uuid.py in uuid5(namespace, name)
606 """Generate a UUID from the SHA-1 hash of a namespace UUID and a name."""
607 from hashlib import sha1
--> 608 hash = sha1(namespace.bytes + bytes(name, "utf-8")).digest()
609 return UUID(bytes=hash[:16], version=5)
610
TypeError: encoding without a string argument
An error occurred when I used an IPV6 address. I shall be glad to receive your reply
I know I suggested it, and I know python2 is EOL, but academic code being what it is... pr coming shortly
Dear @ddetommaso,
May I ask you if you have any tips to use the Tobii Pro Glasses 3 with Python?
Thanks,
How can I get in touch with you on Twitter, Email or other platform?
Hi Davide,
another difference between PIP and GIT versions.
On GIT I receive an Error 400 Bad Request when I start a new recording. It does not happen with PIP code. I cannot test the stop_recording
because I cannot start it.
As we noticed together, and I can confirm the difference in PIP version, is the datetime format:
Cheers,
Dario
HI,
The current Python version is 2.7.18.
Any solution?
Running this on Windows with 64-bit Anaconda 2.7, I get the following error message:
Traceback (most recent call last):
File "connect.py", line 18, in <module>
from tobiiglassesctrl.controller import TobiiGlassesController
File "C:\ProgramData\Anaconda2\lib\site-packages\tobiiglassesctrl\controller.py", line 29, in <module>
import IN
ImportError: No module named IN
It seems to be a somewhat common problem. The module is only used on line 110 (mksock) to import a constant, so it could easily be replaced with the numeric value which is 25.
try:
if iptype == socket.AF_INET6 and sys.platform == "linux2":
sock.setsockopt(socket.SOL_SOCKET, IN.SO_BINDTODEVICE, self.iface_name+'\0')
Hello, thank you for sharing the code in this repo! I'm trying to run the live_scene.py
example, but since my hardware doesn't support WLAN I've needed to use the IPV6 address instead of the IPV4 one. I edited the script to include these lines:
address = "fe80::..." # I put my actual ipv6 address here
cap = cv2.VideoCapture("rtsp://[%s]:8554/live/scene" % address)
Which results in the following error at the cap = cv2.VideoCapture...
line: (I omitted my address here but it does show up in the original error message)
[ERROR:0] global /home/amy/opencv-master/modules/videoio/src/cap.cpp (142) open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.5.0-dev) /home/amy/opencv-master/modules/videoio/src/cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): rtsp://[fe80:...]:8554/live/scene in function 'icvExtractPattern'
Error opening video stream or file
Do you know how to fix this? Thanks in advance!
Is there a reason this package depends on these old but oddly specific versions of opencv-python
and av
?
install_requires=['netifaces', 'opencv-python==4.2.0.32', 'av==8.0.3'],
If not, I'd like to suggest to widen / remove the version specifiers.
As both deps are also not even imported in the installed package, maybe we could drop those entries from the setup.py
altogether, and add a requirements.txt
to the apps folder maybe?
Hello, I was trying to connect my Tobii glasses to the computer via ethernet, and after putting in the correct device IPv6 I encountered this error:
[DEBUG]: Connecting to the Tobii Pro Glasses 2 ... Traceback (most recent call last): File "E:\noticeability-repo\other-python-code\unity_tobii_stream.py", line 25, in <module> tobiiglasses = TobiiGlassesController(ipv6_address) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\tobiiglassesctrl\controller.py", line 96, in __init__ if self.__connect__(timeout = timeout) is False: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\tobiiglassesctrl\controller.py", line 104, in __connect__ self.data_socket = self.__mksock__() ^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\tobiiglassesctrl\controller.py", line 188, in __mksock__ sock.setsockopt(socket.SOL_SOCKET, 25, self.iface_name+'\0') TypeError: a bytes-like object is required, not 'str'
I went through controller.py
, and it seems that for line 188, self.iface_name+'\0' should be
self.iface_name.encode()` instead for proper byte-like encoding.
Hello, I don't know if you remember, but I am a university student living in Korea who studied and inquired about how to utilize data using Tobii in ROS.
Thanks to your kind reply last time, I was able to proceed smoothly with sending and receiving data from ROS.
I'm asking you again because I have a question.
If you run the code 'calibrate_and_record.py', you can see that the data is saved in the form of a json file.
I would like to save this data as a csv file to utilize it smoothly.
So I'm looking at the 'tobiiglassesctrl' module to modify the way data is stored, and I don't know how to approach it.
If you know how, could you give me some advice or hints?
Thank you so much!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.