-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaze_analysis.py
92 lines (68 loc) · 2.69 KB
/
gaze_analysis.py
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
# native
import os
import csv
import cv2
# custom
from pygazeanalyser.edfreader import read_edf
from pygazeanalyser.detectors import fixation_detection
from pygazeanalyser.gazeplotter import draw_fixations, draw_heatmap, draw_scanpath, draw_raw
# external
import numpy
def heatMap(startTime,endTime,totalTime):
#(in seconds) (later converted to millis)
#start time of video segment
#end time of video segment
#total time of video
#saveLocation: location where output heatmap is to be saved
#fixationFilePath: location of fixation csv
#videoLocation: location of video
#imageWidth and IimageHeight: dimension of a frame in a video
saveLocation = '/Users/jeffhe/Desktop/commitments/urap/resources/heatmap_processing/0308_1528_manual_03/heatmat.png'
fixationFilePath = "/Users/jeffhe/Desktop/commitments/urap/resources/heatmap_processing/0308_1528_manual_03/fixations.csv"
gazeFilePath = "/Users/jeffhe/Desktop/commitments/urap/resources/heatmap_processing/0308_1528_manual_03/gaze_positions.csv"
videoLocation = "/Users/jeffhe/Desktop/commitments/urap/resources/heatmap_processing/0308_1528_manual_03/worldwithoutgaze.mp4"
imageWidth = 1280
imageHeight = 720
def changeStartTimeMillis():
with open(gazeFilePath) as f:
reader = csv.reader(f)
reader = list(reader)
startTimeSeconds = float(reader[1][0])
return startTimeSeconds
startTimeMillis = changeStartTimeMillis() * 1000
vidcap = cv2.VideoCapture(videoLocation)
frames = []
success, image = vidcap.read()
frames += [image]
while success:
success, image = vidcap.read()
frames += [image]
startFrame = (startTime / totalTime) * len(frames)
endFrame = (endTime / totalTime) * len(frames)
image = frames[int((startFrame + endFrame) / 2)]
startTime = startTime * 1000
endTime = endTime * 1000
with open(fixationFilePath) as f:
reader = csv.reader(f)
line_num = 0
Efix = []
for row in reader:
if (line_num != 0):
start = float(row[1]) * 1000 - startTimeMillis
Efix += [[start,start + float(row[2]),float(row[2]),int(float(row[5]) * imageWidth),imageHeight - int(float(row[6]) * imageHeight)]]
line_num += 1
i = 0
while (i < len(Efix)):
start = Efix[i][0]
end = Efix[i][1]
print(startTime,end)
if (startTime > end):
Efix.remove(Efix[i])
continue
if (endTime < start):
Efix.remove(Efix[i])
continue
i += 1
draw_heatmap(Efix,(imageWidth,imageHeight),image,savefilename=saveLocation)
print(Efix)
heatMap(44,53,65)