Use uppercase enum constants for RunningMode
PiperOrigin-RevId: 500760402
This commit is contained in:
parent
d40fa6b16d
commit
0831023114
|
@ -21,7 +21,7 @@ import {TaskRunnerOptions} from '../../../../tasks/web/core/task_runner_options'
|
||||||
* 1) The image mode for processing single image inputs.
|
* 1) The image mode for processing single image inputs.
|
||||||
* 2) The video mode for processing decoded frames of a video.
|
* 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. */
|
/** The options for configuring a MediaPipe vision task. */
|
||||||
export declare interface VisionTaskOptions extends TaskRunnerOptions {
|
export declare interface VisionTaskOptions extends TaskRunnerOptions {
|
||||||
|
|
|
@ -118,19 +118,19 @@ describe('VisionTaskRunner', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can enable image mode', async () => {
|
it('can enable image mode', async () => {
|
||||||
await visionTaskRunner.setOptions({runningMode: 'image'});
|
await visionTaskRunner.setOptions({runningMode: 'IMAGE'});
|
||||||
expect(visionTaskRunner.baseOptions.toObject())
|
expect(visionTaskRunner.baseOptions.toObject())
|
||||||
.toEqual(jasmine.objectContaining({useStreamMode: false}));
|
.toEqual(jasmine.objectContaining({useStreamMode: false}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can enable video mode', async () => {
|
it('can enable video mode', async () => {
|
||||||
await visionTaskRunner.setOptions({runningMode: 'video'});
|
await visionTaskRunner.setOptions({runningMode: 'VIDEO'});
|
||||||
expect(visionTaskRunner.baseOptions.toObject())
|
expect(visionTaskRunner.baseOptions.toObject())
|
||||||
.toEqual(jasmine.objectContaining({useStreamMode: true}));
|
.toEqual(jasmine.objectContaining({useStreamMode: true}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can clear running mode', async () => {
|
it('can clear running mode', async () => {
|
||||||
await visionTaskRunner.setOptions({runningMode: 'video'});
|
await visionTaskRunner.setOptions({runningMode: 'VIDEO'});
|
||||||
|
|
||||||
// Clear running mode
|
// Clear running mode
|
||||||
await visionTaskRunner.setOptions(
|
await visionTaskRunner.setOptions(
|
||||||
|
@ -140,7 +140,7 @@ describe('VisionTaskRunner', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cannot process images with video mode', async () => {
|
it('cannot process images with video mode', async () => {
|
||||||
await visionTaskRunner.setOptions({runningMode: 'video'});
|
await visionTaskRunner.setOptions({runningMode: 'VIDEO'});
|
||||||
expect(() => {
|
expect(() => {
|
||||||
visionTaskRunner.processImageData(
|
visionTaskRunner.processImageData(
|
||||||
IMAGE, /* imageProcessingOptions= */ undefined);
|
IMAGE, /* imageProcessingOptions= */ undefined);
|
||||||
|
@ -155,7 +155,7 @@ describe('VisionTaskRunner', () => {
|
||||||
}).toThrowError(/Task is not initialized with video mode./);
|
}).toThrowError(/Task is not initialized with video mode./);
|
||||||
|
|
||||||
// Explicitly set to image mode
|
// Explicitly set to image mode
|
||||||
await visionTaskRunner.setOptions({runningMode: 'image'});
|
await visionTaskRunner.setOptions({runningMode: 'IMAGE'});
|
||||||
expect(() => {
|
expect(() => {
|
||||||
visionTaskRunner.processVideoData(
|
visionTaskRunner.processVideoData(
|
||||||
IMAGE, /* imageProcessingOptions= */ undefined, TIMESTAMP);
|
IMAGE, /* imageProcessingOptions= */ undefined, TIMESTAMP);
|
||||||
|
@ -163,7 +163,7 @@ describe('VisionTaskRunner', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends packets to graph', async () => {
|
it('sends packets to graph', async () => {
|
||||||
await visionTaskRunner.setOptions({runningMode: 'video'});
|
await visionTaskRunner.setOptions({runningMode: 'VIDEO'});
|
||||||
|
|
||||||
visionTaskRunner.expectImage(IMAGE);
|
visionTaskRunner.expectImage(IMAGE);
|
||||||
visionTaskRunner.expectNormalizedRect(0.5, 0.5, 1, 1);
|
visionTaskRunner.expectNormalizedRect(0.5, 0.5, 1, 1);
|
||||||
|
@ -172,7 +172,7 @@ describe('VisionTaskRunner', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends packets to graph with image processing options', async () => {
|
it('sends packets to graph with image processing options', async () => {
|
||||||
await visionTaskRunner.setOptions({runningMode: 'video'});
|
await visionTaskRunner.setOptions({runningMode: 'VIDEO'});
|
||||||
|
|
||||||
visionTaskRunner.expectImage(IMAGE);
|
visionTaskRunner.expectImage(IMAGE);
|
||||||
visionTaskRunner.expectNormalizedRect(0.3, 0.6, 0.2, 0.4);
|
visionTaskRunner.expectNormalizedRect(0.3, 0.6, 0.2, 0.4);
|
||||||
|
|
|
@ -56,7 +56,7 @@ export abstract class VisionTaskRunner extends TaskRunner {
|
||||||
override applyOptions(options: VisionTaskOptions): Promise<void> {
|
override applyOptions(options: VisionTaskOptions): Promise<void> {
|
||||||
if ('runningMode' in options) {
|
if ('runningMode' in options) {
|
||||||
const useStreamMode =
|
const useStreamMode =
|
||||||
!!options.runningMode && options.runningMode !== 'image';
|
!!options.runningMode && options.runningMode !== 'IMAGE';
|
||||||
this.baseOptions.setUseStreamMode(useStreamMode);
|
this.baseOptions.setUseStreamMode(useStreamMode);
|
||||||
}
|
}
|
||||||
return super.applyOptions(options);
|
return super.applyOptions(options);
|
||||||
|
@ -69,7 +69,7 @@ export abstract class VisionTaskRunner extends TaskRunner {
|
||||||
if (!!this.baseOptions?.getUseStreamMode()) {
|
if (!!this.baseOptions?.getUseStreamMode()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Task is not initialized with image mode. ' +
|
'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
|
// 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()) {
|
if (!this.baseOptions?.getUseStreamMode()) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Task is not initialized with video mode. ' +
|
'Task is not initialized with video mode. ' +
|
||||||
'\'runningMode\' must be set to \'video\'.');
|
'\'runningMode\' must be set to \'VIDEO\'.');
|
||||||
}
|
}
|
||||||
this.process(imageFrame, imageProcessingOptions, timestamp);
|
this.process(imageFrame, imageProcessingOptions, timestamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ describe('ImageEmbedder', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('for video mode', async () => {
|
it('for video mode', async () => {
|
||||||
await imageEmbedder.setOptions({runningMode: 'video'});
|
await imageEmbedder.setOptions({runningMode: 'VIDEO'});
|
||||||
|
|
||||||
// Invoke the video embedder
|
// Invoke the video embedder
|
||||||
const embeddingResult =
|
const embeddingResult =
|
||||||
|
|
Loading…
Reference in New Issue
Block a user