我正在尝试使用BodyPix/Tensorflow来模糊网络摄像头的背景。我正在努力遵循这个指南。https://github.com/vinooniv/video-bg-blur的数据。这显然对他们有效,因为他们有一个活生生的例子。
下面是我的代码:
ngOnInit(): void {
const videoElement = document.getElementById('face-blur-video') as HTMLVideoElement
const canvas = document.getElementById('blur-canvas') as HTMLCanvasElement;
videoElement.onplaying = () => {
canvas.height = videoElement.height
canvas.width = videoElement.width
}
const context = canvas.getContext('2d');
context.canvas.height = 320;
context.canvas.height = 480;
navigator.mediaDevices.getUserMedia({video: true, audio: true})
.then(stream => {
videoElement.srcObject = stream;
videoElement.play();
const options: ModelConfig = {
multiplier: .75,
outputStride: 16,
quantBytes: 4,
architecture: 'MobileNetV1'
}
tfjs.getBackend();
BodyPix.load(options).then(bp => this.perform(bp))
})
个字符
但是,当应用程序运行时,我得到以下错误:
core.js:6162 ERROR Error: Uncaught (in promise): InvalidStateError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
Error: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0.
at drawWithCompositing (body-pix.esm.js:17)
at Module.drawBokehEffect (body-pix.esm.js:17)
at FaceBlurComponent.<anonymous> (face-blur.component.ts:56)
at Generator.next (<anonymous>)
at fulfilled (tslib.es6.js:73)
at ZoneDelegate.invoke (zone-evergreen.js:372)
at Object.onInvoke (core.js:28510)
at ZoneDelegate.invoke (zone-evergreen.js:371)
at Zone.run (zone-evergreen.js:134)
at zone-evergreen.js:1276
at resolvePromise (zone-evergreen.js:1213)
at zone-evergreen.js:1120
at zone-evergreen.js:1136
at ZoneDelegate.invoke (zone-evergreen.js:372)
at Object.onInvoke (core.js:28510)
at ZoneDelegate.invoke (zone-evergreen.js:371)
at Zone.run (zone-evergreen.js:134)
at zone-evergreen.js:1276
at ZoneDelegate.invokeTask (zone-evergreen.js:406)
at Object.onInvokeTask (core.js:28497)
型
我已经尽可能地设置了宽度和高度。为什么TensorFlow检测到画布的高度/宽度为零?
3条答案
按热度按时间ztmd8pv51#
所以我最终查看了Google TensorFlow/BodyPix演示并做了一些修改。任何改变都不应该有什么不同,但无论修复是什么,一切都正常工作。下面是我的工作代码:
字符串
我基本上做了一堆异步方法,然后递归地调用绘制效果。我不知道为什么会成功,但确实成功了。
mzillmmw2#
在我的情况下,我正在传输的视频没有宽度和高度,设置此修复此
字符串
ar5n3qh53#
在我的情况下,我传输的视频没有宽度和高度,设置这个固定了这个.非常好的解决方案。
字符串