diff --git a/index.html b/index.html index b69dc8e..36615ff 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,15 @@ + + @@ -275,6 +283,16 @@ } }, 100); + const warmupInterval = setInterval(() => { + if (faceDetector.isReady() && bodyDetector.isReady()) { + clearInterval(warmupInterval); + + document.getElementById("face-detector-ready").innerText = "True"; + document.getElementById("body-detector-ready").innerText = "True"; + document.getElementById("video-input-device-select").disabled = false; + } + }, 100); + const deviceSelect = await Camera.createOrUpdateSelectElement(document.getElementById("video-input-device-select")); deviceSelect.onchange = async () => { try { diff --git a/js/body_detector.js b/js/body_detector.js index c128496..7e80f7c 100644 --- a/js/body_detector.js +++ b/js/body_detector.js @@ -66,6 +66,15 @@ export class BodyDetector { } } + /** + * Determines whether the detector is ready to be used. + * + * @returns {boolean} Whether the detector is ready to be used. + */ + isReady() { + return this.detector != null; + } + /** * Retrieves the most recent runtime of the detector, in milliseconds. * diff --git a/js/face_detector.js b/js/face_detector.js index ada7944..ea3227c 100644 --- a/js/face_detector.js +++ b/js/face_detector.js @@ -66,6 +66,15 @@ export class FaceDetector { } } + /** + * Determines whether the detector is ready to be used. + * + * @returns {boolean} Whether the detector is ready to be used. + */ + isReady() { + return this.detector != null; + } + /** * Retrieves the most recent runtime of the detector, in milliseconds. *