xxxxxxxxxx
69
const video = document.getElementById("myvideo");
const canvas = document.getElementById("canvas");
const context = canvas.getContext("2d");
let trackButton = document.getElementById("trackbutton");
let updateNote = document.getElementById("updatenote");
let isVideo = false;
let model = null;
const modelParams = {
flipHorizontal: true, // flip e.g for video
maxNumBoxes: 2, // maximum number of boxes to detect
iouThreshold: 0.5, // ioU threshold for non-max suppression
scoreThreshold: 0.55, // confidence threshold for predictions.
}
function startVideo() {
handTrack.startVideo(video).then(function (status) {
//console.log("video partito", status);
if (status) {
updateNote.innerText = "Video partito"
isVideo = true
runDetection()
} else {
updateNote.innerText = "Attiva video"
}
});
}
function toggleVideo() {
if (!isVideo) {
updateNote.innerText = "Sta partendo il video"
startVideo();
} else {
updateNote.innerText = "Sto fermando il video"
handTrack.stopVideo(video)
isVideo = false;
updateNote.innerText = "Video fermato"
}
}
function runDetection() {
model.detect(video).then(predictions => {
model.renderPredictions(predictions, canvas, context, video);
if (isVideo) {
requestAnimationFrame(runDetection);
}
});
}
// Load the model.
handTrack.load(modelParams).then(lmodel => {
// detect objects in the image.
model = lmodel
updateNote.innerText = "Modello caricato!"
trackButton.disabled = false
});
function setup() {
// createCanvas(400, 400);
}
function draw() {
//background(220);
}