From 7471bf150a01079fb43102b8f807300cfddf2cfc Mon Sep 17 00:00:00 2001 From: Moe Date: Fri, 22 Mar 2024 15:47:27 -0700 Subject: [PATCH] add more possibilities for event draw on liveGrid --- web/assets/css/bs5.liveGrid.css | 3 +- web/assets/js/bs5.monitorsUtils.js | 63 ++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/web/assets/css/bs5.liveGrid.css b/web/assets/css/bs5.liveGrid.css index aeca4f5b..a2282801 100644 --- a/web/assets/css/bs5.liveGrid.css +++ b/web/assets/css/bs5.liveGrid.css @@ -190,7 +190,8 @@ img.circle-img,div.circle-img{border-radius:50%;height:50px;width:50px} .stream-objects .stream-detected-point{position:absolute;top:0;left:0;border:3px solid yellow;background:transparent;border-radius:5px} .stream-objects .point{position:absolute;top:0;left:0;border:3px solid red;border-radius:50%} .stream-objects .matrix-info{ - margin-top: 20%; background:rgba(0,0,0,0.3);color:#fff; width: 100%; padding: 1rem; font-family:monospace; + margin-top: 4rem; background:rgba(0,0,0,0.3);color:#fff; width: 100%; padding: 1rem; font-family:monospace; z-index: 99; + position: relative; } .stream-objects .matrix-info.yellow{ color: yellow; diff --git a/web/assets/js/bs5.monitorsUtils.js b/web/assets/js/bs5.monitorsUtils.js index a48e46ee..a0e3e84e 100644 --- a/web/assets/js/bs5.monitorsUtils.js +++ b/web/assets/js/bs5.monitorsUtils.js @@ -1,5 +1,6 @@ var monitorGroupSelections = $('#monitor-group-selections') var onGetSnapshotByStreamExtensions = [] +var redAlertNotice = null; function onGetSnapshotByStream(callback){ onGetSnapshotByStreamExtensions.push(callback) } @@ -645,6 +646,42 @@ function launchImportMonitorWindow(callback){ reader.readAsText(f); }); } +function readAlertNotice(title, text, type) { + if (redAlertNotice) { + redAlertNotice.update({ + title: title, + text: text, + type: type, + hide: false, + delay: 30000 + }); + } else { + redAlertNotice = new PNotify({ + title: title, + text: text, + type: type, + hide: false, + delay: 30000 + }); + redAlertNotice.on('close', function() { + redAlertNotice = null; + }); + } +} +function buildPosePoints(bodyParts, x, y){ + let theArray = [] + for(const point of bodyParts){ + theArray.push({ + tag: point.name, + x: x + point.x - 5, // Assuming a 10x10 rectangle for the wrist + y: y + point.y - 5, + width: 10, + height: 10, + confidence: point.score, + }) + } + return theArray; +} function drawMatrices(event,options){ var theContainer = options.theContainer var height = options.height @@ -654,15 +691,17 @@ function drawMatrices(event,options){ var objectTagGroup = event.details.reason === 'motion' ? 'motion' : event.details.name theContainer.find(`.stream-detected-object[name="${objectTagGroup}"]`).remove() var html = '' - $.each(event.details.matrices,function(n,matrix){ + let moreMatrices = [] + var monitorId = event.id; + function processMatrix(n,matrix){ html += `
` if(matrix.tag)html += `${matrix.tag}${!isNaN(matrix.id) ? ` ${matrix.id}`: ''}` if(matrix.notice)html += `
${matrix.notice}
`; if(matrix.missingNear && matrix.missingNear.length > 0){ html += `
Missing Near
${matrix.missingRecently.map(item => `${item.tag} (${item.id}) by ${item.missedNear.tag} (${item.missedNear.id})`).join(', ')}
`; } - if(matrix.missingRecently && matrix.missingRecently.length > 0){ - html += `
Missing Recently
${matrix.missingRecently.map(item => `${item.tag} (${item.id})`).join(', ')}
`; + if(matrix.missingRecentlyNearHands && matrix.missingRecentlyNearHands.length > 0){ + html += `
Missing Recently
${matrix.missingRecentlyNearHands.map(item => `${item.tag} (${item.id})`).join(', ')}
`; } if(matrix.pose){ var pose = matrix.pose; @@ -674,6 +713,16 @@ function drawMatrices(event,options){ } // if(pose.isPersonTouchingWaistOrHips)html += `
Waist or Hips : ${pose.isPersonTouchingWaistOrHips}
`; html += `
`; + // console.log(matrix.poseInference) + } + if(matrix.poseInference)moreMatrices.push(...buildPosePoints(matrix.poseInference.keypoints,matrix.x,matrix.y)) + if(matrix.nearHands){ + var leftHand = matrix.nearHands.leftWrist; + var rightHand = matrix.nearHands.rightWrist; + html += `
` + html += `
Left Interact
${leftHand.matrices.map(item => `${item.tag} (${item.id})`).join(', ')}
`; + html += `
Right Interact
${rightHand.matrices.map(item => `${item.tag} (${item.id})`).join(', ')}
`; + html += `
` } if(matrix.nearBy){ html += `
` @@ -682,8 +731,14 @@ function drawMatrices(event,options){ }); html += `
` } + if(matrix.redAlert){ + var monitor = loadedMonitors[monitorId] + readAlertNotice(`${monitor.name}`,`${matrix.tag} (${matrix.id})
${matrix.notice}`,'danger'); + } html += '' - }) + } + $.each(event.details.matrices, processMatrix); + $.each(moreMatrices, processMatrix); theContainer.append(html) } function setMonitorCountOnUI(){