-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
93 lines (69 loc) · 2.41 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- bootstrap cdn -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.css" integrity="sha256-Nfu23DiRqsrx/6B6vsI0T9vEVKq1M6KgO8+TV363g3s=" crossorigin="anonymous" />
<title>Webgazer</title>
</head>
<body>
<style>
body{
background-image: url('test.png');
}
button {
float: right !important;
margin: 3px;
}
</style>
<div onclick="saveGaze()" class="ml-auto">
<button class="btn btn-light">Save</button>
</div>
<div onclick="webgazer.resume()">
<button class="btn btn-light">Resume</button>
</div>
<div onclick="webgazer.pause()">
<button class="btn btn-light">Pause</button>
</div>
<div onclick="recordGaze()">
<button class="btn btn-light">Start</button>
</div>
<script>
// this array will store all the eye movements
var x = [];
// start recording
function recordGaze() {
webgazer.setGazeListener(function (data, elapsedTime) {
if (data == null) {
return;
}
var xprediction = data.x;
var yprediction = data.y;
var save_url = "https://anupm12.github.io/Eye-tracking-WebGazer.js/?"+"x="+xprediction+";y="+yprediction;
var temp_image = new Image();
temp_image.src= save_url;
x.push([xprediction, yprediction]);
console.log(xprediction + "," + yprediction);
}).begin();
}
// exporting data to .csv file
function saveGaze() {
console.log(x);
var csv = '';
x.forEach(function (row) {
csv += row.join(',');
csv += "\n";
});
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
hiddenElement.target = '_blank';
hiddenElement.download = 'gazeData.csv';
hiddenElement.click();
}
</script>
</body>
<script src="webgazer.js" type="text/javascript">
</script>
</html>