Skip to content

Commit

Permalink
Update BodyDetector and FaceDetector to initialize their internal…
Browse files Browse the repository at this point in the history
… detectors as soon as they're created, so that they're "warmed up" by the time the user needs them

Update UI to represent "readyness" of `BodyDetector` and `FaceDetector` and to prevent the user from selecting a video input device until the detectors are ready
  • Loading branch information
Valkryst committed Nov 22, 2023
1 parent ec8aba7 commit 69e056b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
20 changes: 19 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@

<label>
Select a Video Input Device:
<select name="video-input-devices" id="video-input-device-select"></select>
<select disabled name="video-input-devices" id="video-input-device-select"></select>
</label>
<label>
Body Detector Ready:
<span id="body-detector-ready">False</span>
</label>
<label>
Face Detector Ready:
<span id="face-detector-ready">False</span>
</label>
</fieldset>

Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions js/body_detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 9 additions & 0 deletions js/face_detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 69e056b

Please sign in to comment.