Skip to content

Commit 6e39666

Browse files
wait for model being loaded before processing video frames
1 parent c9a1e5f commit 6e39666

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/views/faceDetectionVideo.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<div class="indeterminate"></div>
1616
</div>
1717
<div style="position: relative" class="margin">
18-
<video src="media/bbt.mp4" onplay="onPlay(this)" autoplay muted></video>
18+
<video src="media/bbt.mp4" onplay="onPlay(this)" id="inputVideo" autoplay muted></video>
1919
<canvas id="overlay" />
2020
</div>
2121
<div class="row side-by-side">
@@ -50,6 +50,7 @@
5050

5151
<script>
5252
let minConfidence = 0.7
53+
let modelLoaded = false
5354
let result
5455

5556
function onIncreaseThreshold() {
@@ -68,7 +69,7 @@
6869
}
6970

7071
async function onPlay(videoEl) {
71-
if(videoEl.paused || videoEl.ended)
72+
if(videoEl.paused || videoEl.ended || !modelLoaded)
7273
return false
7374

7475
const input = await faceapi.toNetInput(videoEl)
@@ -87,6 +88,8 @@
8788

8889
async function run() {
8990
await faceapi.loadFaceDetectionModel('/')
91+
modelLoaded = true
92+
onPlay($('#inputVideo').get(0))
9093
$('#loader').hide()
9194
}
9295

0 commit comments

Comments
 (0)