license import { getObjectScale } from '../calculators/get_object_scale' ; import { ImageSize , Keypoint , KeypointsFilter } from '../calculators/interfaces/common_interfaces' ; import { KeypointsSmoothingConfig } from '../calculators/interfaces/config_interfaces' ; import { Rect } from '../calculators/interfaces/shape_interfaces' ; import { keypointsToNormalizedKeypoints } from '../calculators/keypoints_to_normalized_keypoints' ; import { normalizedKeypointsToKeypoints } from '../calculators/normalized_keypoints_to_keypoints' ; import { KeypointsOneEuroFilter } from './keypoints_one_euro_filter' ; import { KeypointsVelocityFilter } from './keypoints_velocity_filter' ; /**
 * A Calculator to smooth keypoints over time.
 */ export class KeypointsSmoothingFilter { private readonly keypointsFilter : KeypointsFilter ; constructor ( config ) { if ( config . velocityFilter != null ) { this . keypointsFilter = new KeypointsVelocityFilter ( config . velocityFilter ) ; } else if ( config . oneEuroFilter != null ) { this . keypointsFilter = new KeypointsOneEuroFilter ( config . oneEuroFilter ) ; } else { throw new Error ( 'Either configure velocityFilter or oneEuroFilter, but got ' + `${ config }.` ) ; } } param keypoints param timestamp param imageSize param normalized param objectScaleROI apply ( keypoints , timestamp , imageSize ? , normalized = false , objectScaleROI ? ) { if ( keypoints == null ) { this . keypointsFilter . reset ( ) ; return null ; } const objectScale = objectScaleROI != null ? getObjectScale ( objectScaleROI , imageSize ) : 1 ; const scaledKeypoints = normalized ? normalizedKeypointsToKeypoints ( keypoints , imageSize ) : keypoints ; const scaledKeypointsFiltered = this . keypointsFilter . apply ( scaledKeypoints , timestamp , objectScale ) ; return normalized ? keypointsToNormalizedKeypoints ( scaledKeypointsFiltered , imageSize ) : scaledKeypointsFiltered ; } }