Process Frame
MovementAnalyzer
API Reference for MovementAnalyzer functions
MovementAnalyzer
is a Guru Analyzer
that provides helper analysis methods related to human movement. It is useful for building fitness or sport-focused apps.
Functions
repsByKeypointDistance
This function, given the frames of a person, find repetitions of a movement defined by the movement between two keypoints. For example, you could use Keypoint.rightHip
and Keypoint.rightAnkle
to count the number of squat reps in a video.
/**
* Find the repetitions of a movement a person is performing, by measuring
* the distance over time between two keypoints. For example, if a person
* is performing a squat, then measuring the distance between hips and ankles
* will give a good signal for identifying squat reps.
*
* By default this function will identify when the two keypoints get closer together
* and count that as a rep. If reps should instead be counted by the keypoints getting
* further apart, set
*
* @param {[FrameObject]} personFrames - The location of the person in each frame of the video.
* @param {Keypoint} keypoint1 - The first keypoint to measure between.
* @param {Keypoint} keypoint2 - The second keypoint to measure between.
* @param {boolean} keypointsContract - True if a rep is identified as the distance between the keypoints contracting.
* Set to false if the keypoint distance expands during a rep. Defaults true.
* @param {number} threshold - The distance required between the keypoints before a rep is counted.
* This number is abstract, it does not translate directly to pixel distance.
* @param {number} smoothing - How much smoothing should be applied to keypoints before reps are counted.
* Higher values will apply more smoothing, which can help with lower quality or obscured videos.
* @param {number} ignoreStartMs - The number of milliseconds to ignore at the start of the video when counting reps.
* If null, attempts to estimate the start time. Default null.
* @param {number} ignoreEndMs - The number of milliseconds to ignore at the end of the video when counting reps.
* If null, attempts to estimate the end time. Default null.
* @returns {[]} - An array of objects, each one having a start, middle, and end property that is
* the millisecond timestamp of the boundaries for that rep.
*/
static repsByKeypointDistance(
personFrames,
keypoint1,
keypoint2, {
keypointsContract = true,
threshold = 0.2,
smoothing = 2.0,
ignoreStartMs = null,
ignoreEndMs = null,
} = {}) {
Example
async function analyzeVideo(frameResults) {
const personId = frameResults.objectIds("person")[0];
const personFrames = frameResults.objectFrames(personId);
const reps = MovementAnalyzer.repsByKeypointDistance(
personFrames,
Keypoint.rightHip,
Keypoint.rightAnkle
);
return {
reps: reps,
};
}
personMostlyFacing
Given the frames of a person, determine which direction they were mostly facing during the course of the video. Returns a value from the ObjectFacing enum.
/**
* Determines which direction the person is mostly facing throughout the video.
*
* @param {[FrameObject]} personFrames - The frames of the person.
* @return {ObjectFacing} The direction that the person is mostly facing throughout the video.
*/
static personMostlyFacing(personFrames) {
personMostlyStanding
Given the frames of a person, determine whether they were standing for the majority of the video. Returns a boolean.
/**
* Determines if the person is mostly standing upright throughout the video or not.
* If false, then they are likely lying down.
*
* @param {[FrameObject]} personFrames - The frames of the person.
* @return {boolean} True if the person is mostly standing up in the video.
*/
static personMostlyStanding(personFrames) {