From f6d0a5e03a793c5ddafbcca93267e03364d075c7 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 5 May 2023 14:27:11 -0700 Subject: [PATCH] Make the timestamp the second argument in all xForVideo() methods PiperOrigin-RevId: 529814792 --- .../web/vision/face_stylizer/face_stylizer.ts | 32 +++++++++---------- .../vision/image_segmenter/image_segmenter.ts | 32 ++++++++----------- .../vision/pose_landmarker/pose_landmarker.ts | 30 ++++++++--------- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/mediapipe/tasks/web/vision/face_stylizer/face_stylizer.ts b/mediapipe/tasks/web/vision/face_stylizer/face_stylizer.ts index 641ab61d..8169e677 100644 --- a/mediapipe/tasks/web/vision/face_stylizer/face_stylizer.ts +++ b/mediapipe/tasks/web/vision/face_stylizer/face_stylizer.ts @@ -261,16 +261,17 @@ export class FaceStylizer extends VisionTaskRunner { * monotonically increasing. * * @param videoFrame A video frame to process. + * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. - * @param timestamp The timestamp of the current frame, in ms. * @param callback The callback that is invoked with the stylized image or * `null` if no face was detected. The lifetime of the returned data is only * guaranteed for the duration of the callback. */ stylizeForVideo( - videoFrame: ImageSource, imageProcessingOptions: ImageProcessingOptions, - timestamp: number, callback: FaceStylizerCallback): void; + videoFrame: ImageSource, timestamp: number, + imageProcessingOptions: ImageProcessingOptions, + callback: FaceStylizerCallback): void; /** * Performs face stylization on the provided video frame. This method creates * a copy of the resulting image and should not be used in high-throughput @@ -307,30 +308,29 @@ export class FaceStylizer extends VisionTaskRunner { * monotonically increasing. * * @param videoFrame A video frame to process. + * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. - * @param timestamp The timestamp of the current frame, in ms. * @return A stylized face or `null` if no face was detected. The result is * copied to avoid lifetime issues. */ - stylizeForVideo( - videoFrame: ImageSource, imageProcessingOptions: ImageProcessingOptions, - timestamp: number): MPImage|null; stylizeForVideo( videoFrame: ImageSource, - timestampOrImageProcessingOptions: number|ImageProcessingOptions, - timestampOrCallback?: number|FaceStylizerCallback, + timestamp: number, + imageProcessingOptions: ImageProcessingOptions, + ): MPImage|null; + stylizeForVideo( + videoFrame: ImageSource, timestamp: number, + imageProcessingOptionsOrCallback?: ImageProcessingOptions| + FaceStylizerCallback, callback?: FaceStylizerCallback): MPImage|null|void { const imageProcessingOptions = - typeof timestampOrImageProcessingOptions !== 'number' ? - timestampOrImageProcessingOptions : + typeof imageProcessingOptionsOrCallback !== 'function' ? + imageProcessingOptionsOrCallback : {}; - const timestamp = typeof timestampOrImageProcessingOptions === 'number' ? - timestampOrImageProcessingOptions : - timestampOrCallback as number; - this.userCallback = typeof timestampOrCallback === 'function' ? - timestampOrCallback : + this.userCallback = typeof imageProcessingOptionsOrCallback === 'function' ? + imageProcessingOptionsOrCallback : callback; this.processVideoData(videoFrame, imageProcessingOptions, timestamp); this.userCallback = undefined; diff --git a/mediapipe/tasks/web/vision/image_segmenter/image_segmenter.ts b/mediapipe/tasks/web/vision/image_segmenter/image_segmenter.ts index 4d0ac18f..b4e9f804 100644 --- a/mediapipe/tasks/web/vision/image_segmenter/image_segmenter.ts +++ b/mediapipe/tasks/web/vision/image_segmenter/image_segmenter.ts @@ -293,16 +293,17 @@ export class ImageSegmenter extends VisionTaskRunner { * created with running mode `video`. * * @param videoFrame A video frame to process. + * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input frame before running inference. - * @param timestamp The timestamp of the current frame, in ms. * @param callback The callback that is invoked with the segmented masks. The * lifetime of the returned data is only guaranteed for the duration of the * callback. */ segmentForVideo( - videoFrame: ImageSource, imageProcessingOptions: ImageProcessingOptions, - timestamp: number, callback: ImageSegmenterCallback): void; + videoFrame: ImageSource, timestamp: number, + imageProcessingOptions: ImageProcessingOptions, + callback: ImageSegmenterCallback): void; /** * Performs image segmentation on the provided video frame and returns the * segmentation result. This method creates a copy of the resulting masks and @@ -322,31 +323,26 @@ export class ImageSegmenter extends VisionTaskRunner { * the ImageSegmenter is created with running mode `video`. * * @param videoFrame A video frame to process. + * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input frame before running inference. - * @param timestamp The timestamp of the current frame, in ms. * @return The segmentation result. The data is copied to avoid lifetime * issues. */ segmentForVideo( - videoFrame: ImageSource, - imageProcessingOptions: ImageProcessingOptions, - timestamp: number, - ): ImageSegmenterResult; + videoFrame: ImageSource, timestamp: number, + imageProcessingOptions: ImageProcessingOptions): ImageSegmenterResult; segmentForVideo( - videoFrame: ImageSource, - timestampOrImageProcessingOptions: number|ImageProcessingOptions, - timestampOrCallback?: number|ImageSegmenterCallback, + videoFrame: ImageSource, timestamp: number, + imageProcessingOptionsOrCallback?: ImageProcessingOptions| + ImageSegmenterCallback, callback?: ImageSegmenterCallback): ImageSegmenterResult|void { const imageProcessingOptions = - typeof timestampOrImageProcessingOptions !== 'number' ? - timestampOrImageProcessingOptions : + typeof imageProcessingOptionsOrCallback !== 'function' ? + imageProcessingOptionsOrCallback : {}; - const timestamp = typeof timestampOrImageProcessingOptions === 'number' ? - timestampOrImageProcessingOptions : - timestampOrCallback as number; - this.userCallback = typeof timestampOrCallback === 'function' ? - timestampOrCallback : + this.userCallback = typeof imageProcessingOptionsOrCallback === 'function' ? + imageProcessingOptionsOrCallback : callback; this.reset(); diff --git a/mediapipe/tasks/web/vision/pose_landmarker/pose_landmarker.ts b/mediapipe/tasks/web/vision/pose_landmarker/pose_landmarker.ts index 7c274306..7cb37d5e 100644 --- a/mediapipe/tasks/web/vision/pose_landmarker/pose_landmarker.ts +++ b/mediapipe/tasks/web/vision/pose_landmarker/pose_landmarker.ts @@ -297,16 +297,17 @@ export class PoseLandmarker extends VisionTaskRunner { * with running mode `video`. * * @param videoFrame A video frame to process. + * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. - * @param timestamp The timestamp of the current frame, in ms. * @param callback The callback that is invoked with the result. The * lifetime of the returned masks is only guaranteed for the duration of * the callback. */ detectForVideo( - videoFrame: ImageSource, imageProcessingOptions: ImageProcessingOptions, - timestamp: number, callback: PoseLandmarkerCallback): void; + videoFrame: ImageSource, timestamp: number, + imageProcessingOptions: ImageProcessingOptions, + callback: PoseLandmarkerCallback): void; /** * Performs pose detection on the provided video frame and returns the result. * This method creates a copy of the resulting masks and should not be used @@ -328,29 +329,26 @@ export class PoseLandmarker extends VisionTaskRunner { * with running mode `video`. * * @param videoFrame A video frame to process. + * @param timestamp The timestamp of the current frame, in ms. * @param imageProcessingOptions the `ImageProcessingOptions` specifying how * to process the input image before running inference. - * @param timestamp The timestamp of the current frame, in ms. * @return The landmarker result. Any masks are copied to extend the lifetime * of the returned data. */ detectForVideo( - videoFrame: ImageSource, imageProcessingOptions: ImageProcessingOptions, - timestamp: number): PoseLandmarkerResult; + videoFrame: ImageSource, timestamp: number, + imageProcessingOptions: ImageProcessingOptions): PoseLandmarkerResult; detectForVideo( - videoFrame: ImageSource, - timestampOrImageProcessingOptions: number|ImageProcessingOptions, - timestampOrCallback?: number|PoseLandmarkerCallback, + videoFrame: ImageSource, timestamp: number, + imageProcessingOptionsOrCallback?: ImageProcessingOptions| + PoseLandmarkerCallback, callback?: PoseLandmarkerCallback): PoseLandmarkerResult|void { const imageProcessingOptions = - typeof timestampOrImageProcessingOptions !== 'number' ? - timestampOrImageProcessingOptions : + typeof imageProcessingOptionsOrCallback !== 'function' ? + imageProcessingOptionsOrCallback : {}; - const timestamp = typeof timestampOrImageProcessingOptions === 'number' ? - timestampOrImageProcessingOptions : - timestampOrCallback as number; - this.userCallback = typeof timestampOrCallback === 'function' ? - timestampOrCallback : + this.userCallback = typeof imageProcessingOptionsOrCallback === 'function' ? + imageProcessingOptionsOrCallback : callback; this.resetResults();