Flipfly alarm tuning example
DEPLOYED
by morphcast
HTML
<head>
<title>MorphCast AI HTML5 SDK - Flipfly - ALARM only - demo example</title>
</head>
<body>
<script src="https://ai-sdk.morphcast.com/v1.15/ai-sdk.js"></script>
<video id="video1" muted playsinline></video>
<div>
<button id="toggle">Pause</button>
</div><br />
<div><b>DEMO per testare i moduli ALARM.<br />Nota:</b> gli output degli ALARM entrano in azione solo dopo un ritardo iniziale (<i>initialToleranceMs</i> = 7 secondi)</div><br />
Alarm modules results: <div id="results">-</div>
</body>
JavaScript 1.7
/*
Creates a pre-built camera source
*/
const cameraSource = CY.createSource.fromCamera({
constraints: {
audio: false,
video: {
width: {
min: 600,
max: 800
}
}
},
video: document.getElementById("video1")
});
CY.loader()
.licenseKey('f2fddf1df7c30cac7908d10246256efd264ce7aa32ec') // key for flipfly
.source(cameraSource)
//.addModule(CY.modules().FACE_DETECTOR.name)
.addModule(CY.modules().ALARM_NO_FACE.name, {
timeWindowMs: 10000,
initialToleranceMs: 7000,
threshold: 0.75
})
.addModule(CY.modules().FACE_ATTENTION.name, {
riseSmoothness: 0.83, // fattore di smorzamento temporale della salita, da 0 (smorzamento minimo) ad 1 (smorzamento)
fallSmoothness: 0.83, // idem, per la discesa
//smoothness: 0.83, // unico parametro per configurare in contemporanea gli smorzamenti sopra
})
.addModule(CY.modules().ALARM_LOW_ATTENTION.name, {
timeWindowMs: 10000,
initialToleranceMs: 7000,
threshold: 0.75
})
.addModule(CY.modules().ALARM_MORE_FACES.name, {
timeWindowMs: 3000,
initialToleranceMs: 7000,
threshold: 0.33
})
.maxInputFrameSize(640)
.load().then(({
start,
stop,
terminate,
getModule
}) => {
const toggle = document.querySelector('#toggle');
var playing = false;
toggle.textContent = 'START SDK';
toggle.onclick = function() {
if (playing) {
stop();
playing = false;
toggle.textContent = 'Resume';
} else {
start();
playing = true;
toggle.textContent = 'Pause';
}
};
setTimeout(() => {
stop();
terminate();
console.log('terminated');
alert('TERMINATED');
}, 200000);
}).catch((err) => {
console.error(err);
});
window.addEventListener(CY.modules().EVENT_BARRIER.eventName, (evt) => {
console.log(CY.modules().EVENT_BARRIER.eventName, evt.detail);
//document.getElementById('results').innerHTML =...