# Plot points sequentially (eye movements), updated in each new frame

**URL:** <https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821>\
**Category:** Python\
**Created:** [March 4, 2022, 7:13pm UTC](https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821 "2022-03-04T19:13:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ric\_usp](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Ric\_usp](https://forum.opencv.org/u/Ric_usp)\
**Post date:** [March 4, 2022, 7:13pm UTC](https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821/1 "2022-03-04T19:13:42Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [March 5, 2022, 7:23am UTC](https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821/2 "2022-03-05T07:23:37Z")

</div>

> [@Ric\_usp](#):
>
> I have an array of points (coordinates x-y) in a 1000 Hz frequency.

what _exactly_ do you have there ? how is it structured ?

---

<div class="post-metadata">

**Author:** ![Ric\_usp](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Ric\_usp](https://forum.opencv.org/u/Ric_usp)\
**Post date:** [March 5, 2022, 12:21pm UTC](https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821/3 "2022-03-05T12:21:34Z")

</div>

It is a numpy array of shape (241001, 2).

```auto
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.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 5, 2022, 2:26pm UTC](https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821/4 "2022-03-05T14:26:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ric\_usp](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Ric\_usp](https://forum.opencv.org/u/Ric_usp)\
**Post date:** [March 5, 2022, 4:27pm UTC](https://forum.opencv.org/t/plot-points-sequentially-eye-movements-updated-in-each-new-frame/7821/5 "2022-03-05T16:27:39Z")

</div>

Thanks, crackwitz!!  
It seems to be working (I could only try on Google Colab), thanks a lot!

What I did, for future reference:

```auto
def create_idx_frames(last_frame):
  frames = list(range(last_frame))
  idxs = [np.int32(i/60 * 1000) for i in frames]
  return idxs

```

```auto
idxs = create_idx_frames(last_frame=np.int32(frame_count))

```

```auto
  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))

```
