@vonage/ml-transformers 1.3.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +3 -1
  2. package/dist/docs/assets/highlight.css +11 -4
  3. package/dist/docs/assets/main.js +2 -2
  4. package/dist/docs/assets/search.js +1 -1
  5. package/dist/docs/assets/style.css +3 -2
  6. package/dist/docs/classes/MediapipeHelper.html +1 -0
  7. package/dist/docs/enums/BlurRadius.html +4 -4
  8. package/dist/docs/index.html +4 -3
  9. package/dist/docs/interfaces/FaceDetectionOptions.html +3 -0
  10. package/dist/docs/interfaces/FaceDetectionResults.html +3 -0
  11. package/dist/docs/interfaces/FaceMeshOptions.html +3 -0
  12. package/dist/docs/interfaces/FaceMeshResults.html +3 -0
  13. package/dist/docs/interfaces/HandsOptions.html +3 -0
  14. package/dist/docs/interfaces/HandsResults.html +3 -0
  15. package/dist/docs/interfaces/HolisticOptions.html +3 -0
  16. package/dist/docs/interfaces/HolisticResults.html +3 -0
  17. package/dist/docs/interfaces/ObjectronOptions.html +3 -0
  18. package/dist/docs/interfaces/ObjectronResults.html +3 -0
  19. package/dist/docs/interfaces/PoseOptions.html +3 -0
  20. package/dist/docs/interfaces/PoseResults.html +3 -0
  21. package/dist/docs/interfaces/SelfieSegmentationOptions.html +3 -0
  22. package/dist/docs/interfaces/SelfieSegmentationResults.html +3 -0
  23. package/dist/docs/modules.html +76 -12
  24. package/dist/ml-transformers.es.js +500 -82
  25. package/dist/ml-transformers.umd.js +4 -4
  26. package/dist/types/main.d.ts +28 -12
  27. package/dist/types/src/transformers/BackgroundTransformer.d.ts +19 -17
  28. package/dist/types/src/transformers/BlurPostProcess.d.ts +1 -0
  29. package/dist/types/src/transformers/MediapipeHelper.d.ts +12 -0
  30. package/dist/types/src/transformers/PostProcessInterface.d.ts +1 -0
  31. package/dist/types/src/transformers/SilueteBlurPostProcess.d.ts +1 -0
  32. package/dist/types/src/transformers/VideoPostProcess.d.ts +8 -5
  33. package/dist/types/src/transformers/VirtualPostProcess.d.ts +5 -5
  34. package/dist/types/src/types.d.ts +71 -17
  35. package/dist/types/src/vonage/VonageAssetsLoaderHelper.d.ts +5 -0
  36. package/dist/types/src/vonage/VonageMediaProcessorThread.d.ts +3 -2
  37. package/dist/types/src/vonage/VonageMediaProcessorWorker.d.ts +16 -5
  38. package/package.json +12 -4
  39. package/dist/models/selfie_segmentation_landscape.tflite +0 -0
  40. package/dist/tflite-simd.wasm +0 -0
  41. package/dist/types/src/transformers/VonageTFLite.d.ts +0 -28
@@ -1,35 +1,37 @@
1
1
  /// <reference types="dom-webcodecs" />
2
2
  /// <reference types="offscreencanvas" />
3
- import { MediaProcessorConfig } from '../../main';
3
+ import { BackgroundOptions } from '../../main';
4
4
  import { PostProcessInterface } from './PostProcessInterface';
5
- import { VonageTFLiteInfo } from './VonageTFLite';
5
+ export declare type ProcessFrame = (image: ImageBitmap) => (void);
6
6
  declare class BackgroundTransformer {
7
7
  static BLUR_PROCESS_GAP_MICRO_SECOND: number;
8
8
  static VIRTUAL_PROCESS_GAP_MICRO_SECOND: number;
9
- voangeTFLiteInfo_: VonageTFLiteInfo;
10
- frameCounter_: number;
9
+ static NEW_INPUT_NUMBER_OF_RUNS: number;
10
+ static SELFIE_WIDTH: number;
11
+ static SELFIE_HIGHT: number;
11
12
  lastProcessedTimestamp_: number;
12
13
  timerGap_: number;
13
- segmentationMaskCanvas_: OffscreenCanvas;
14
- segmentationMaskCtx_: OffscreenCanvasRenderingContext2D | null;
15
- segmentationPixelCount_: number;
16
- segmentationMask_: ImageData;
17
- segmentationMaskFrameCanvas_: OffscreenCanvas;
18
- segmentationMaskFrameCtx_: OffscreenCanvasRenderingContext2D | null;
14
+ processFrameCb?: ProcessFrame;
15
+ segmentationMaskImage_?: ImageBitmap;
16
+ segmentationMaskCanvas_?: OffscreenCanvas;
17
+ segmentationMaskCtx_?: OffscreenCanvasRenderingContext2D | null;
19
18
  resultCanvas_: OffscreenCanvas;
20
19
  resultCtx_: OffscreenCanvasRenderingContext2D | null;
21
- inputMemoryOffset_: number;
22
- outputMemoryOffset_: number;
23
20
  postProcessInterface_?: PostProcessInterface;
24
- config_: MediaProcessorConfig;
25
- constructor(config: MediaProcessorConfig);
26
- init(): Promise<void>;
27
- start(): Promise<void>;
21
+ newInputCounter: number;
22
+ constructor();
23
+ init(framProcessor: ProcessFrame): void;
24
+ setBackgroundOptions(backgroundOptions: BackgroundOptions): Promise<void>;
25
+ close(): Promise<void>;
26
+ start(): void;
28
27
  transform(frame: any, controller: TransformStreamDefaultController): Promise<void>;
29
28
  processFrame(controller: TransformStreamDefaultController, image: ImageBitmap, timestamp: number): void;
30
29
  processSource(image: ImageBitmap): void;
31
30
  flush(): void;
32
31
  getTransformerType(): string;
33
- setVideoBGReadable(videoBGReadable: ReadableStream): void;
32
+ resetNewInputCouner(): void;
33
+ setVideoBGReadable(videoBGReadable: ReadableStream): Promise<void>;
34
+ setVirtualBGImage(image: ImageBitmap): Promise<void>;
35
+ setSegmentationMaskImage(image: ImageBitmap): void;
34
36
  }
35
37
  export default BackgroundTransformer;
@@ -5,6 +5,7 @@ import { BlurRadius } from "../types";
5
5
  declare class BlurPostProcess implements PostProcessInterface {
6
6
  blurFilter_: string;
7
7
  constructor(radius?: BlurRadius);
8
+ destroy(): Promise<void>;
8
9
  runPostProcessing(resultCtx: OffscreenCanvasRenderingContext2D | null, image: ImageBitmap): void;
9
10
  }
10
11
  export default BlurPostProcess;
@@ -0,0 +1,12 @@
1
+ import { MediapipeConfig, MediaPipeModelType } from '../types';
2
+ declare class MediapipeHelper {
3
+ private mediapipeMap_;
4
+ private static defaultAssetsBaseUrl;
5
+ constructor();
6
+ private getVersion;
7
+ initialize(config: MediapipeConfig): Promise<void>;
8
+ close(modelType?: MediaPipeModelType): Promise<void>;
9
+ send(image: HTMLVideoElement | HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas, modelType?: MediaPipeModelType): Promise<void>;
10
+ reset(modelType?: MediaPipeModelType): void;
11
+ }
12
+ export default MediapipeHelper;
@@ -2,4 +2,5 @@
2
2
  /// <reference types="offscreencanvas" />
3
3
  export interface PostProcessInterface {
4
4
  runPostProcessing(resultCtx: OffscreenCanvasRenderingContext2D | null, image: ImageBitmap): void;
5
+ destroy(): Promise<void>;
5
6
  }
@@ -5,6 +5,7 @@ import { BlurRadius } from '../types';
5
5
  declare class SilueteBlurPostProcess implements PostProcessInterface {
6
6
  blurFilter_: string;
7
7
  constructor(radius?: BlurRadius);
8
+ destroy(): Promise<void>;
8
9
  runPostProcessing(resultCtx: OffscreenCanvasRenderingContext2D | null, image: ImageBitmap): void;
9
10
  }
10
11
  export default SilueteBlurPostProcess;
@@ -1,11 +1,14 @@
1
1
  /// <reference types="dom-webcodecs" />
2
2
  /// <reference types="offscreencanvas" />
3
3
  import { PostProcessInterface } from './PostProcessInterface';
4
- import { Queue } from './Queue';
5
4
  export declare class VideoPostProcess implements PostProcessInterface {
6
- queue_: Queue<any>;
7
- frameReader_: any;
8
- constructor(videoBGReadable: ReadableStream);
9
- processFrame(result: any): void;
5
+ private queue_;
6
+ private frameReader_?;
7
+ private static NUMBER_OF_FRAMES_TO_CLEAR;
8
+ constructor();
9
+ private clearQueue;
10
+ setVideoReadable(videoBGReadable: ReadableStream): Promise<void>;
11
+ destroy(): Promise<void>;
12
+ private processFrame;
10
13
  runPostProcessing(resultCtx: OffscreenCanvasRenderingContext2D | null, image: ImageBitmap): void;
11
14
  }
@@ -2,10 +2,10 @@
2
2
  /// <reference types="offscreencanvas" />
3
3
  import { PostProcessInterface } from "./PostProcessInterface";
4
4
  declare class VirtualPostProcess implements PostProcessInterface {
5
- imageCanvas_: OffscreenCanvas;
6
- imageCtx_: OffscreenCanvasRenderingContext2D | null;
7
- imageBlob_: any;
8
- constructor(imageUri: string);
9
- runPostProcessing(resultCtx: OffscreenCanvasRenderingContext2D | null, image: ImageBitmap): void;
5
+ bgImage_?: ImageBitmap;
6
+ constructor();
7
+ destroy(): Promise<void>;
8
+ setVirtualBGImage(image: ImageBitmap): void;
9
+ runPostProcessing(resultCtx: OffscreenCanvasRenderingContext2D | null, image: ImageBitmap): Promise<void>;
10
10
  }
11
11
  export default VirtualPostProcess;
@@ -1,3 +1,10 @@
1
+ import { Results as FaceDetectionResults, Options as FaceDetectionOptions } from '@mediapipe/face_detection';
2
+ import { Results as FaceMeshResults, Options as FaceMeshOptions } from '@mediapipe/face_mesh';
3
+ import { Results as HandsResults, Options as HandsOptions } from '@mediapipe/hands';
4
+ import { Results as HolisticResults, Options as HolisticOptions } from '@mediapipe/holistic';
5
+ import { Results as ObjectronResults, Options as ObjectronOptions } from '@mediapipe/objectron';
6
+ import { Results as SelfieSegmentationResults, Options as SelfieSegmentationOptions } from '@mediapipe/selfie_segmentation';
7
+ import { Results as PoseResults, Options as PoseOptions } from '@mediapipe/pose';
1
8
  /**
2
9
  * VonageTransformerType which type of transformer to create.
3
10
  */
@@ -16,24 +23,32 @@ export declare enum BlurRadius {
16
23
  High = "High"
17
24
  }
18
25
  /**
19
- * MediaProcessorBaseConfig specifies the absolute URL for the path where the Wasm modules used by the transformers from this library are stored.
20
- *
21
- * @example
22
- *
23
- * ```ts
24
- * {
25
- * wasmAssetUriPath: 'http://localhost:8080/assets'
26
- * tfliteAssetUriPath: 'http://localhost:8080/assets'
27
- * }
28
- * ```
29
- * wasmAssetUriPath - should be the uri path to `tflite-simd.wasm` which included in the package under ./dist
30
- * tfliteAssetUriPath - should be the uri path to `selfie_segmentation_landscape.tflite` which included in the package under ./dist/models
31
- * the libary will load this files while starting the transformer process. the load will be on web worker.
32
- *
33
- */
26
+ * MediaProcessorBaseConfig specifies the absolute URL for the path where the mediapipe assets used by the transformers from this library are stored.
27
+ * Vonage hosts static assets of mediapipe that will be used in case this property is not set.
28
+ * Vonage promises to take care of maintaining all versioning.
29
+ *
30
+ * @example
31
+ *
32
+ * ```ts
33
+ * {
34
+ * mediapipeBaseAssetsUri: 'http://localhost:8080/assets' | undeifined
35
+ * }
36
+ * ```
37
+ * mediapipeBaseAssetsUri - should be the uri path to mediapipe assets.
38
+ * *** WARNING *** - using this option moves the responsibility of the assets and the versioning to the user.
39
+ * mediapipe selfie segmintaion got those assets:
40
+ * selfie_segmentation_landscape.tflite
41
+ * selfie_segmentation_solution_simd_wasm_bin.js
42
+ * selfie_segmentation_solution_simd_wasm_bin.wasm
43
+ * selfie_segmentation_solution_wasm_bin.js
44
+ * selfie_segmentation_solution_wasm_bin.wasm
45
+ * selfie_segmentation.binarypb
46
+ * selfie_segmentation.tflite
47
+ * please keep in mind that the assets list can change between versions!
48
+ * all assets can be taken from `node_modules/@mediapipe/selfie_segmentation`
49
+ */
34
50
  export declare type MediaProcessorBaseConfig = {
35
- wasmAssetUriPath: string;
36
- tfliteAssetUriPath: string;
51
+ mediapipeBaseAssetsUri?: string;
37
52
  };
38
53
  /**
39
54
  * BackgroundBlurConfig specifies the configuration for a transformer logic that performs background blurring.
@@ -67,3 +82,42 @@ export declare type SilueteBlurConfig = {
67
82
  transformerType: 'SilueteBlur';
68
83
  radius?: BlurRadius;
69
84
  };
85
+ export type { FaceDetectionResults, FaceDetectionOptions, FaceMeshResults, FaceMeshOptions, HandsResults, HandsOptions, HolisticResults, HolisticOptions, ObjectronResults, ObjectronOptions, SelfieSegmentationResults, SelfieSegmentationOptions, PoseResults, PoseOptions };
86
+ /**
87
+ * MediaPipeResults types of results object of MediaPipe
88
+ */
89
+ export declare type MediaPipeResults = FaceDetectionResults | FaceMeshResults | HandsResults | HolisticResults | ObjectronResults | SelfieSegmentationResults;
90
+ /**
91
+ * ResultsListener callback function from MediaPipe process
92
+ * @results - The results object from MediaPipe
93
+ * @returns - can return a promise of void
94
+ */
95
+ export declare type MediaPipeResultsListener = <T extends MediaPipeResults>(results: T) => (Promise<void> | void);
96
+ /**
97
+ * MediaPipeModelType supported models types
98
+ */
99
+ export declare type MediaPipeModelType = "face_mesh" | "face_detection" | "hands" | "holistic" | "objectron" | "selfie_segmentation" | 'pose';
100
+ /**
101
+ * defines one mediapipe model config
102
+ * @modelType - which model is required
103
+ * @listener - callback function from the model
104
+ * @options - define options for the mediapipe model that is used. for more info check https://google.github.io/mediapipe/getting_started/javascript.html
105
+ * @assetsUri (optional) - can be set to get wasm/tflite/js/binarypb assets. Vonage provides static assets.
106
+ * *** WARNING *** - using this option moves the responsibility of the assets and the versioning to the user.
107
+ * please keep in mind that the assets list can change between versions!
108
+ * assets are different between mediapipe models.
109
+ */
110
+ export declare type MediaPipeModelConfig = {
111
+ modelType: MediaPipeModelType;
112
+ listener: MediaPipeResultsListener;
113
+ options: FaceDetectionOptions | FaceMeshOptions | HandsOptions | HolisticOptions | ObjectronOptions | SelfieSegmentationOptions;
114
+ assetsUri?: string;
115
+ };
116
+ /**
117
+ * MediapipeConfig specified config of mediapipe helper:
118
+ * this structure allows the user to create few mediapipe models that will run in parallel.
119
+ * @modelTypesArray - array of mediapipe models to be loaded and called.
120
+ */
121
+ export declare type MediapipeConfig = {
122
+ mediaPipeModelConfigArray: Array<MediaPipeModelConfig>;
123
+ };
@@ -0,0 +1,5 @@
1
+ declare class VonageAssetsLoaderHelper {
2
+ static createVideoReadable(videoUri: string): Promise<ReadableStream>;
3
+ static createImageCanvas(imageUri: string): Promise<ImageBitmap>;
4
+ }
5
+ export default VonageAssetsLoaderHelper;
@@ -1,5 +1,6 @@
1
- export declare type CallbackType = 'success' | 'error' | 'media_processor_error_event' | 'media_processor_warn_event';
1
+ export declare type CallbackType = 'success' | 'error' | 'media_processor_error_event' | 'media_processor_warn_event' | 'media_processor_pipeline_event';
2
2
  export declare type CallbackMessage = {
3
3
  callbackType: CallbackType;
4
- message: any;
4
+ message?: any;
5
+ error?: string;
5
6
  };
@@ -1,16 +1,27 @@
1
1
  import { EventDataMap, MediaProcessorInterface } from '@vonage/media-processor';
2
- import { MediaProcessorConfig } from '../../main';
2
+ import { BackgroundOptions, MediaProcessorConfig } from '../../main';
3
3
  import Emittery from 'emittery';
4
+ import MediapipeHelper from '../transformers/MediapipeHelper';
5
+ interface InnerEventDataMap {
6
+ initResults: string;
7
+ transformResults: string;
8
+ destroyResults: string;
9
+ setBackgroundOptionsResults: string;
10
+ setVideoBGReadableResults: string;
11
+ setVirtualBGImageResults: string;
12
+ }
4
13
  declare class VonageMediaProcessorWorker extends Emittery<EventDataMap> implements MediaProcessorInterface {
5
- worker_: any;
6
- config_: MediaProcessorConfig;
7
- onMessage_: Promise<void>;
14
+ worker_?: any;
8
15
  trackExpectedRate_: number;
9
16
  workerInited_: boolean;
10
- constructor(config: MediaProcessorConfig);
17
+ mediapipeHelper_: MediapipeHelper;
18
+ innerEmitty_: Emittery<InnerEventDataMap>;
19
+ constructor();
20
+ init(config: MediaProcessorConfig): Promise<void>;
11
21
  transform(readable: ReadableStream, writable: WritableStream): Promise<void>;
12
22
  destroy(): Promise<void>;
13
23
  setTrackExpectedRate(trackExpectedRate: number): void;
14
24
  postTrackExpectedRate(): void;
25
+ setBackgroundOptions(backgroundOptions: BackgroundOptions): Promise<void>;
15
26
  }
16
27
  export default VonageMediaProcessorWorker;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonage/ml-transformers",
3
- "version": "1.3.1",
3
+ "version": "2.0.2",
4
4
  "author": "Guy Mininberg <guy.mininberg@vonage.com>",
5
5
  "contributors": [
6
6
  "Guy Mininberg <guy.mininberg@vonage.com>",
@@ -37,7 +37,15 @@
37
37
  "axios": "^0.25.0",
38
38
  "uuid": "^8.3.2",
39
39
  "typescript-optional": "3.0.0-alpha.3",
40
- "@vonage/media-processor": "1.2.1"
40
+ "@vonage/media-processor": "1.2.7",
41
+ "@mediapipe/selfie_segmentation": "0.1.1632777926",
42
+ "@mediapipe/hands": "0.4.1646424915",
43
+ "@mediapipe/objectron": "0.4.1636596145",
44
+ "@mediapipe/face_mesh": "0.4.1633559619",
45
+ "@mediapipe/face_detection": "0.4.1646425229",
46
+ "@mediapipe/holistic": "0.5.1635989137",
47
+ "@mediapipe/pose": "0.5.1635988162",
48
+ "@mediapipe/drawing_utils": "0.3.1620248257"
41
49
  },
42
50
  "files": [
43
51
  "dist"
@@ -54,11 +62,11 @@
54
62
  "devDependencies": {
55
63
  "@tsconfig/node12": "^1.0.1",
56
64
  "typescript": "^4.5.4",
57
- "vite": "^2.7.2",
65
+ "vite": "2.9.9",
58
66
  "npm-run-all": "^4.1.5",
59
67
  "typedoc": "^0.22.12"
60
68
  },
61
- "repository": "https://github.com/vonage/ml-transformers",
69
+ "repository": "https://github.com/Vonage/vonage-media-transformers-samples",
62
70
  "publishConfig": {
63
71
  "registry": "https://registry.npmjs.org"
64
72
  }
Binary file
@@ -1,28 +0,0 @@
1
- /// <reference types="emscripten" />
2
- export interface TFLite extends EmscriptenModule {
3
- _getModelBufferMemoryOffset(): number;
4
- _getInputMemoryOffset(): number;
5
- _getInputHeight(): number;
6
- _getInputWidth(): number;
7
- _getInputChannelCount(): number;
8
- _getOutputMemoryOffset(): number;
9
- _getOutputHeight(): number;
10
- _getOutputWidth(): number;
11
- _getOutputChannelCount(): number;
12
- _loadModel(bufferSize: number): number;
13
- _runInference(): number;
14
- }
15
- export declare class VonageTFLiteInfo {
16
- selectedTFLite_: TFLite;
17
- isSIMDSupported_: boolean;
18
- isThreadsSupported_: boolean;
19
- inputWidth_: number;
20
- inputHeight_: number;
21
- inputChannelCount_: number;
22
- inputMemoryOffset_: number;
23
- outputWidth_: number;
24
- outputHeight_: number;
25
- outputChannelCount_: number;
26
- outputMemoryOffset_: number;
27
- }
28
- export declare function VonageTFLite(wasmUri: string, tfliteUri: string): Promise<VonageTFLiteInfo>;