Adds a public function for creating TaskRunner instances.
PiperOrigin-RevId: 493109736
This commit is contained in:
parent
4f8eaee20f
commit
69b27b246a
|
@ -32,19 +32,13 @@ const GraphRunnerImageLibType =
|
|||
/** An implementation of the GraphRunner that supports image operations */
|
||||
export class GraphRunnerImageLib extends GraphRunnerImageLibType {}
|
||||
|
||||
/** Base class for all MediaPipe Tasks. */
|
||||
export abstract class TaskRunner<O extends TaskRunnerOptions> {
|
||||
protected abstract baseOptions: BaseOptionsProto;
|
||||
protected graphRunner: GraphRunnerImageLib;
|
||||
private processingErrors: Error[] = [];
|
||||
|
||||
/**
|
||||
/**
|
||||
* Creates a new instance of a Mediapipe Task. Determines if SIMD is
|
||||
* supported and loads the relevant WASM binary.
|
||||
* @return A fully instantiated instance of `T`.
|
||||
*/
|
||||
protected static async createInstance<T extends TaskRunner<O>,
|
||||
O extends TaskRunnerOptions>(
|
||||
export async function
|
||||
createTaskRunner<T extends TaskRunner<O>, O extends TaskRunnerOptions>(
|
||||
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
|
||||
fileset: WasmFileset, options: O): Promise<T> {
|
||||
const fileLocator: FileLocator = {
|
||||
|
@ -64,6 +58,24 @@ export abstract class TaskRunner<O extends TaskRunnerOptions> {
|
|||
type, fileset.wasmLoaderPath, NO_ASSETS, canvas, fileLocator);
|
||||
await instance.setOptions(options);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** Base class for all MediaPipe Tasks. */
|
||||
export abstract class TaskRunner<O extends TaskRunnerOptions> {
|
||||
protected abstract baseOptions: BaseOptionsProto;
|
||||
protected graphRunner: GraphRunnerImageLib;
|
||||
private processingErrors: Error[] = [];
|
||||
|
||||
/**
|
||||
* Creates a new instance of a Mediapipe Task. Determines if SIMD is
|
||||
* supported and loads the relevant WASM binary.
|
||||
* @return A fully instantiated instance of `T`.
|
||||
*/
|
||||
protected static async createInstance<T extends TaskRunner<O>,
|
||||
O extends TaskRunnerOptions>(
|
||||
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
|
||||
fileset: WasmFileset, options: O): Promise<T> {
|
||||
return createTaskRunner(type, initializeCanvas, fileset, options);
|
||||
}
|
||||
|
||||
constructor(
|
||||
|
|
Loading…
Reference in New Issue
Block a user