mirror of https://github.com/vladmandic/human
fix demo facecompare
parent
7ba3f9b24e
commit
4596666c0d
|
@ -176,7 +176,7 @@ const compare = { enabled: false, original: null };
|
||||||
async function calcSimmilariry(result) {
|
async function calcSimmilariry(result) {
|
||||||
document.getElementById('compare-container').style.display = compare.enabled ? 'block' : 'none';
|
document.getElementById('compare-container').style.display = compare.enabled ? 'block' : 'none';
|
||||||
if (!compare.enabled) return;
|
if (!compare.enabled) return;
|
||||||
if (!result || !result.face || result.face[0].embedding) return;
|
if (!result || !result.face || !result.face[0].embedding) return;
|
||||||
if (!(result.face.length > 0) || (result.face[0].embedding.length <= 64)) return;
|
if (!(result.face.length > 0) || (result.face[0].embedding.length <= 64)) return;
|
||||||
if (!compare.original) {
|
if (!compare.original) {
|
||||||
compare.original = result;
|
compare.original = result;
|
||||||
|
@ -274,6 +274,7 @@ async function drawResults(input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup webcam
|
// setup webcam
|
||||||
|
let initialCameraAccess = true;
|
||||||
async function setupCamera() {
|
async function setupCamera() {
|
||||||
if (ui.busy) return null;
|
if (ui.busy) return null;
|
||||||
ui.busy = true;
|
ui.busy = true;
|
||||||
|
@ -305,10 +306,11 @@ async function setupCamera() {
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
// enumerate devices for diag purposes
|
// enumerate devices for diag purposes
|
||||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
if (initialCameraAccess) {
|
||||||
log('enumerated devices:');
|
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||||
for (const device of devices) log(` kind:${device.kind} label:${device.label} id:${device.deviceId}`);
|
log('enumerated devices:');
|
||||||
|
for (const device of devices) log(` kind:${device.kind} label:${device.label} id:${device.deviceId}`);
|
||||||
|
}
|
||||||
let stream;
|
let stream;
|
||||||
const constraints = {
|
const constraints = {
|
||||||
audio: false,
|
audio: false,
|
||||||
|
@ -349,9 +351,10 @@ async function setupCamera() {
|
||||||
}
|
}
|
||||||
const track = stream.getVideoTracks()[0];
|
const track = stream.getVideoTracks()[0];
|
||||||
const settings = track.getSettings();
|
const settings = track.getSettings();
|
||||||
log('selected camera:', track.label, 'id:', settings.deviceId);
|
if (initialCameraAccess) log('selected camera:', track.label, 'id:', settings.deviceId);
|
||||||
// log('camera constraints:', constraints, 'window:', { width: window.innerWidth, height: window.innerHeight }, 'settings:', settings, 'track:', track);
|
// log('camera constraints:', constraints, 'window:', { width: window.innerWidth, height: window.innerHeight }, 'settings:', settings, 'track:', track);
|
||||||
ui.camera = { name: track.label.toLowerCase(), width: settings.width, height: settings.height, facing: settings.facingMode === 'user' ? 'front' : 'back' };
|
ui.camera = { name: track.label.toLowerCase(), width: settings.width, height: settings.height, facing: settings.facingMode === 'user' ? 'front' : 'back' };
|
||||||
|
initialCameraAccess = false;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
video.onloadeddata = async () => {
|
video.onloadeddata = async () => {
|
||||||
video.width = video.videoWidth;
|
video.width = video.videoWidth;
|
||||||
|
|
Loading…
Reference in New Issue