brownhci / WebGazer

WebGazer.js: Scalable Webcam EyeTracking Using User Interactions
https://webgazer.cs.brown.edu
Other
3.54k stars 536 forks source link

Can I listen to an event that fires when eyes are inside/outside of validation box? #169

Open tpronk opened 4 years ago

tpronk commented 4 years ago

Hi!

For some context: I'm a developer with PsychoJS (software for psychological experiments online) and built a simple prototype that integrates webgazer into our system. The prototype was intended as a tech demo, but this demo received quite some attention, so now I'd like to improve the calibration a bit.

My current goal is to show the video feedback thumbnail only when the participant's eyes are outside of the validation box, so I'd like to listen to an event that fires when their eyes are inside/outside of the validation box. Do you know of an elegant way of achieving this?

Thanks , Thomas

Skylion007 commented 4 years ago

@xanderkoo ? If we don't have a listener that supports your needs, happy to add one. Maybe we can add a listener to the get the screen the coordinates of the bounding box if we don't have one already.

xanderkoo commented 4 years ago

There isn't a listener per se, but there is a function that detects whether the eyes are within the box or not. Check out the function checkEyesInValidationBox() in index.mjs, which determines if the eyes are inside the validation box and updates the color of the box accordingly, although there isn't a return value/event associated with this function.

@Skylion007 Should I modify checkEyesInValidationBox() so that it triggers a custom event? Or have it return a boolean? (Also it could be useful to split the function into checkEyesInValidationBox() and updateValidationBox() or something).

@tpronk In the meantime, if you're building from source, you should be able to modify it such that it returns a boolean or spawns an event.

tpronk commented 4 years ago

Thanks for the pointers @Skylion007 and @xanderkoo! Today my CPU is busy running some simulations, so I can't yet try out the solutions you propose, but I think you provided enough info to solve my problem. I'll try to implement it tomorrow:

tpronk commented 4 years ago

Made a branch that exposes a modified version of checkEyesInValidationBox() as a function of webgazer. It returns true if eyes are inside of validation box; false if outside, and undefined if no eyes are registered in the webcam feed. The link below is a PsychoJS where I used the modified webgazer library. Thanks again for your help! https://gitlab.pavlovia.org/tpronk/demo_eye_tracking2