Hi!!
I have an array of points (coordinates x-y) in a 1000 Hz frequency. They are eye movements.
And I have a video of 60 fps.
I want to draw those points, that will be more than one per frame.
But the drawing will be cleared every new frame.
How can I do that?
I tried cv.polylines(frame, [points], …) but they are plotted all at once.
Thanks!!
berak
March 5, 2022, 7:23am
2
what exactly do you have there ? how is it structured ?
It is a numpy array of shape (241001, 2).
array([[1163.3494 , 319.2574 ],
[1165.903 , 319.27826],
[1165.0868 , 320.85303],
...,
[1016.2021 , 531.86115],
[1016.11816, 531.4956 ],
[1017.2184 , 533.5527 ]], dtype=float32)
The video has frame size (1680.0, 1050.0), fps = 60.0, frame count = 14424.0 and duration of 240.4 seconds.
Thanks, berak.
so… what you could do is for every video frame, calculate the time (seconds = frame number / 60), and then calculate the current index in the gaze data (index = seconds * 1000), and then take, say, 16.67, or 50, or 500, or however many samples, and draw them into the frame. you could draw points, or lines, or make a heatmap.
Thanks, crackwitz!!
It seems to be working (I could only try on Google Colab), thanks a lot!
What I did, for future reference:
def create_idx_frames(last_frame):
frames = list(range(last_frame))
idxs = [np.int32(i/60 * 1000) for i in frames]
return idxs
idxs = create_idx_frames(last_frame=np.int32(frame_count))
frame_number = np.int32(cap.get(cv.CAP_PROP_POS_FRAMES))
idx_current = idxs[frame_number]
idx_past = idxs[frame_number-1]
cv.polylines(frame, np.int32([eyes[idx_past:idx_current, :]]), isClosed=False, color=(255, 255, 255))