-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2024 New Vector Ltd. | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
Please see LICENSE in the repository root for full details. | ||
*/ | ||
|
||
import { | ||
BackgroundTransformer, | ||
VideoTransformer, | ||
VideoTransformerInitOptions, | ||
} from "@livekit/track-processors"; | ||
import { ImageSegmenter } from "@mediapipe/tasks-vision"; | ||
|
||
interface WasmFileset { | ||
/** The path to the Wasm loader script. */ | ||
wasmLoaderPath: string; | ||
/** The path to the Wasm binary. */ | ||
wasmBinaryPath: string; | ||
} | ||
|
||
// n.b. this only includes the SIMD versions of the WASM files which have good support: | ||
// https://caniuse.com/?search=simd | ||
const wasmFileset: WasmFileset = { | ||
wasmLoaderPath: new URL( | ||
"../../node_modules/@mediapipe/tasks-vision/wasm/vision_wasm_internal.js", | ||
import.meta.url, | ||
).href, | ||
wasmBinaryPath: new URL( | ||
"../../node_modules/@mediapipe/tasks-vision/wasm/vision_wasm_internal.wasm", | ||
import.meta.url, | ||
).href, | ||
}; | ||
|
||
const modelAssetPath = new URL( | ||
"../mediapipe/imageSegmenter/selfie_segmenter.tflite", | ||
import.meta.url, | ||
).href; | ||
|
||
export class BlurBackgroundTransformer extends BackgroundTransformer { | ||
public async init({ | ||
outputCanvas, | ||
inputElement: inputVideo, | ||
}: VideoTransformerInitOptions): Promise<void> { | ||
// call super.super.init() | ||
await VideoTransformer.prototype.init.call(this, { | ||
outputCanvas, | ||
inputElement: inputVideo, | ||
}); | ||
|
||
this.imageSegmenter = await ImageSegmenter.createFromOptions(wasmFileset, { | ||
baseOptions: { | ||
modelAssetPath, | ||
delegate: "GPU", | ||
...this.options.segmenterOptions, | ||
}, | ||
runningMode: "VIDEO", | ||
outputCategoryMask: true, | ||
outputConfidenceMasks: false, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Google AI Edge MediaPipe Selfie Segmentation | ||
|
||
- See: https://ai.google.dev/edge/mediapipe/solutions/vision/image_segmenter | ||
- Latest: https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_segmenter/float16/latest/selfie_segmenter.tflite | ||
- License: Apache 2.0 as per https://storage.googleapis.com/mediapipe-assets/Model%20Card%20MediaPipe%20Selfie%20Segmentation.pdf |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1840,6 +1840,11 @@ | |
resolved "https://registry.yarnpkg.com/@mediapipe/tasks-vision/-/tasks-vision-0.10.9.tgz#fbd669f50ac2e888b2c64c9c9863927c111da02f" | ||
integrity sha512-/gFguyJm1ng4Qr7VVH2vKO+zZcQd8wc3YafUfvBuYFX0Y5+CvrV+VNPEVkl5W/gUZF5KNKNZAiaHPULGPCIjyQ== | ||
|
||
"@mediapipe/tasks-vision@^0.10.18": | ||
version "0.10.18" | ||
resolved "https://registry.yarnpkg.com/@mediapipe/tasks-vision/-/tasks-vision-0.10.18.tgz#9ea0f0bf7506378c55ee661fa70aa0910f21f9b5" | ||
integrity sha512-NRIlyqhGUz1Jdgcs6YybwPRhLK6dgeGAqAMXepIczEQ7FmA/0ouFtgMO1g9SPf/HaDSO8pNVdP54dAb9s9wj/Q== | ||
|
||
"@nodelib/[email protected]": | ||
version "2.1.5" | ||
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" | ||
|