From 08310231145b3c82e3d72effa49e081960b6be58 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Mon, 9 Jan 2023 11:09:28 -0800 Subject: [PATCH] Use uppercase enum constants for RunningMode PiperOrigin-RevId: 500760402 --- .../tasks/web/vision/core/vision_task_options.d.ts | 2 +- .../web/vision/core/vision_task_runner.test.ts | 14 +++++++------- .../tasks/web/vision/core/vision_task_runner.ts | 6 +++--- .../vision/image_embedder/image_embedder_test.ts | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mediapipe/tasks/web/vision/core/vision_task_options.d.ts b/mediapipe/tasks/web/vision/core/vision_task_options.d.ts index 76c0177a0..44b1660ff 100644 --- a/mediapipe/tasks/web/vision/core/vision_task_options.d.ts +++ b/mediapipe/tasks/web/vision/core/vision_task_options.d.ts @@ -21,7 +21,7 @@ import {TaskRunnerOptions} from '../../../../tasks/web/core/task_runner_options' * 1) The image mode for processing single image inputs. * 2) The video mode for processing decoded frames of a video. */ -export type RunningMode = 'image'|'video'; +export type RunningMode = 'IMAGE'|'VIDEO'; /** The options for configuring a MediaPipe vision task. */ export declare interface VisionTaskOptions extends TaskRunnerOptions { diff --git a/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts b/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts index a48381038..4567134b8 100644 --- a/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts +++ b/mediapipe/tasks/web/vision/core/vision_task_runner.test.ts @@ -118,19 +118,19 @@ describe('VisionTaskRunner', () => { }); it('can enable image mode', async () => { - await visionTaskRunner.setOptions({runningMode: 'image'}); + await visionTaskRunner.setOptions({runningMode: 'IMAGE'}); expect(visionTaskRunner.baseOptions.toObject()) .toEqual(jasmine.objectContaining({useStreamMode: false})); }); it('can enable video mode', async () => { - await visionTaskRunner.setOptions({runningMode: 'video'}); + await visionTaskRunner.setOptions({runningMode: 'VIDEO'}); expect(visionTaskRunner.baseOptions.toObject()) .toEqual(jasmine.objectContaining({useStreamMode: true})); }); it('can clear running mode', async () => { - await visionTaskRunner.setOptions({runningMode: 'video'}); + await visionTaskRunner.setOptions({runningMode: 'VIDEO'}); // Clear running mode await visionTaskRunner.setOptions( @@ -140,7 +140,7 @@ describe('VisionTaskRunner', () => { }); it('cannot process images with video mode', async () => { - await visionTaskRunner.setOptions({runningMode: 'video'}); + await visionTaskRunner.setOptions({runningMode: 'VIDEO'}); expect(() => { visionTaskRunner.processImageData( IMAGE, /* imageProcessingOptions= */ undefined); @@ -155,7 +155,7 @@ describe('VisionTaskRunner', () => { }).toThrowError(/Task is not initialized with video mode./); // Explicitly set to image mode - await visionTaskRunner.setOptions({runningMode: 'image'}); + await visionTaskRunner.setOptions({runningMode: 'IMAGE'}); expect(() => { visionTaskRunner.processVideoData( IMAGE, /* imageProcessingOptions= */ undefined, TIMESTAMP); @@ -163,7 +163,7 @@ describe('VisionTaskRunner', () => { }); it('sends packets to graph', async () => { - await visionTaskRunner.setOptions({runningMode: 'video'}); + await visionTaskRunner.setOptions({runningMode: 'VIDEO'}); visionTaskRunner.expectImage(IMAGE); visionTaskRunner.expectNormalizedRect(0.5, 0.5, 1, 1); @@ -172,7 +172,7 @@ describe('VisionTaskRunner', () => { }); it('sends packets to graph with image processing options', async () => { - await visionTaskRunner.setOptions({runningMode: 'video'}); + await visionTaskRunner.setOptions({runningMode: 'VIDEO'}); visionTaskRunner.expectImage(IMAGE); visionTaskRunner.expectNormalizedRect(0.3, 0.6, 0.2, 0.4); diff --git a/mediapipe/tasks/web/vision/core/vision_task_runner.ts b/mediapipe/tasks/web/vision/core/vision_task_runner.ts index 9ed9ffdb2..71cac920c 100644 --- a/mediapipe/tasks/web/vision/core/vision_task_runner.ts +++ b/mediapipe/tasks/web/vision/core/vision_task_runner.ts @@ -56,7 +56,7 @@ export abstract class VisionTaskRunner extends TaskRunner { override applyOptions(options: VisionTaskOptions): Promise { if ('runningMode' in options) { const useStreamMode = - !!options.runningMode && options.runningMode !== 'image'; + !!options.runningMode && options.runningMode !== 'IMAGE'; this.baseOptions.setUseStreamMode(useStreamMode); } return super.applyOptions(options); @@ -69,7 +69,7 @@ export abstract class VisionTaskRunner extends TaskRunner { if (!!this.baseOptions?.getUseStreamMode()) { throw new Error( 'Task is not initialized with image mode. ' + - '\'runningMode\' must be set to \'image\'.'); + '\'runningMode\' must be set to \'IMAGE\'.'); } // Increment the timestamp by 1 millisecond to guarantee that we send @@ -86,7 +86,7 @@ export abstract class VisionTaskRunner extends TaskRunner { if (!this.baseOptions?.getUseStreamMode()) { throw new Error( 'Task is not initialized with video mode. ' + - '\'runningMode\' must be set to \'video\'.'); + '\'runningMode\' must be set to \'VIDEO\'.'); } this.process(imageFrame, imageProcessingOptions, timestamp); } diff --git a/mediapipe/tasks/web/vision/image_embedder/image_embedder_test.ts b/mediapipe/tasks/web/vision/image_embedder/image_embedder_test.ts index 01ec751e3..5a8293c44 100644 --- a/mediapipe/tasks/web/vision/image_embedder/image_embedder_test.ts +++ b/mediapipe/tasks/web/vision/image_embedder/image_embedder_test.ts @@ -143,7 +143,7 @@ describe('ImageEmbedder', () => { }); it('for video mode', async () => { - await imageEmbedder.setOptions({runningMode: 'video'}); + await imageEmbedder.setOptions({runningMode: 'VIDEO'}); // Invoke the video embedder const embeddingResult =