Give real-time targets proportional alpha values (#169)

Closes: #158

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>

Reviewed-on: #169
This commit is contained in:
2024-03-31 09:56:49 -07:00
parent 33b50f3dfd
commit e1464df3f0
2 changed files with 6 additions and 2 deletions

View File

@@ -368,6 +368,7 @@ import { Conv2DBackpropFilter } from '@tensorflow/tfjs'
imCanvas.width = imCanvas.clientWidth imCanvas.width = imCanvas.clientWidth
imCanvas.height = imCanvas.clientHeight imCanvas.height = imCanvas.clientHeight
imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height) imageCtx.clearRect(0,0,imCanvas.width,imCanvas.height)
imageCtx.globalAlpha = 1
imageCtx.strokeStyle = 'yellow' imageCtx.strokeStyle = 'yellow'
imageCtx.lineWidth = 3 imageCtx.lineWidth = 3
return [imCanvas, imageCtx] return [imCanvas, imageCtx]

View File

@@ -196,9 +196,11 @@ export default {
let rawCoords = [] let rawCoords = []
if (rawRes) { if (rawRes) {
for (var i = 0; i < rawRes.length; i++) { for (var i = 0; i < rawRes.length; i++) {
var getScores = rawRes[i].slice(4) let getScores = rawRes[i].slice(4)
if (getScores.some( s => s > .5)) { if (getScores.some( s => s > .5)) {
rawCoords.push(rawRes[i].slice(0,2)) let foundTarget = rawRes[i].slice(0,2)
foundTarget.push(Math.max(...getScores))
rawCoords.push(foundTarget)
} }
} }
@@ -207,6 +209,7 @@ export default {
console.log(`x: ${coord[0]}, y: ${coord[1]}`) console.log(`x: ${coord[0]}, y: ${coord[1]}`)
let pointX = (imCanvas.width - imgWidth) / 2 + (coord[0] / modelWidth) * imgWidth -5 let pointX = (imCanvas.width - imgWidth) / 2 + (coord[0] / modelWidth) * imgWidth -5
let pointY = (imCanvas.height - imgHeight) / 2 + (coord[1] / modelHeight) * imgHeight -5 let pointY = (imCanvas.height - imgHeight) / 2 + (coord[1] / modelHeight) * imgHeight -5
imageCtx.globalAlpha = coord[2]
imageCtx.drawImage(target, pointX, pointY, 20, 20) imageCtx.drawImage(target, pointX, pointY, 20, 20)
} }
} }