Video Analysis#

video_plot()#

video_plot(video, sampling_rate=30, frames=3, signals=None)[source]#

Visualize video

This function plots a few frames from a video as an image.

Parameters:
  • video (np.ndarray) – An video data numpy array of the shape (frame, channel, height, width)

  • sampling_rate (int) – The number of frames per second (FPS), by default 30.

  • frames (int or list) – What frames to plot. If list, indicates the index of frames. If number, will select linearly spaced frames.

  • signals (list) – A list of signals to plot under the videos.

Examples

In [1]: import neurokit2 as nk

# video, sampling_rate = nk.read_video("video.mp4")
# nk.video_plot(video, sampling_rate=sampling_rate)

video_face()#

video_face(video, verbose=True)[source]#

Extract face from video

This function extracts the faces from a video. This function requires the cv2, `menpo and menpodetect modules to be installed.

Note

This function is experimental. If you are interested in helping us improve that aspect of NeuroKit (e.g., by adding more detection algorithms), please get in touch!

Parameters:
  • video (np.ndarray) – An video data numpy array of the shape (frame, channel, height, width)

  • verbose (bool) – Whether to print the progress bar.

Returns:

list – A list of cropped faces.

Examples

In [1]: import neurokit2 as nk

# video, sampling_rate = nk.read_video("video.mp4")
# faces = nk.video_face(video)
# nk.video_plot([video, faces])

video_skin()#

video_skin(face, show=False)[source]#

Skin detection

This function detects the skin in a face.

Note

This function is experimental. If you are interested in helping us improve that aspect of NeuroKit (e.g., by adding more detection algorithms), please get in touch!

Parameters:
  • face (np.ndarray) – A face data numpy array of the shape (channel, height, width).

  • show (bool) – Whether to show the skin detection mask.

Returns:

np.ndarray – A skin detection mask.

See also

video_face, video_ppg

Examples

In [1]: import neurokit2 as nk

# video, sampling_rate = nk.read_video("video.mp4")
# faces = nk.video_face(video)
# skin = nk.video_skin(faces[0], show=True)

video_ppg()#

video_ppg(video, sampling_rate=30, verbose=True)[source]#

Remote Photoplethysmography (rPPG) from Video

Extracts the photoplethysmogram (PPG) from a webcam video using the Plane-Orthogonal-to-Skin (POS) algorithm.

Note

This function is experimental and does NOT seem to work at all (DominiqueMakowski/RemotePhysiology). If you are interested in helping us improve that aspect of NeuroKit (e.g., by adding more detection algorithms), please get in touch!

Parameters:
  • video (np.ndarray) – A video data numpy array of the shape (frame, channel, height, width).

  • sampling_rate (int) – The sampling rate of the video, by default 30 fps (a common sampling rate for commercial webcams).

  • verbose (bool) – Whether to print the progress bar.

Returns:

np.ndarray – A PPG signal.

Examples

In [1]: import neurokit2 as nk

# video, sampling_rate = nk.read_video("video.mp4")
# ppg = nk.video_ppg(video)

References

  • Wang, W., Den Brinker, A. C., Stuijk, S., & De Haan, G. (2016). Algorithmic principles of remote PPG. IEEE Transactions on Biomedical Engineering, 64(7), 1479-1491.