-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { FilesetResolver, ObjectDetector } from '@mediapipe/tasks-vision'; | ||
|
||
export default async function cargarModelo(nivelConfianza: number) { | ||
const vision = await FilesetResolver.forVisionTasks('https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision/wasm'); | ||
|
||
return await ObjectDetector.createFromOptions(vision, { | ||
baseOptions: { | ||
modelAssetPath: `https://storage.googleapis.com/mediapipe-models/object_detector/efficientdet_lite0/float16/1/efficientdet_lite0.tflite`, | ||
delegate: 'GPU', | ||
}, | ||
scoreThreshold: nivelConfianza, | ||
runningMode: 'VIDEO', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,80 @@ | ||
import type { Aparicion, Cuadro } from '../tipos'; | ||
import categoriasConColor from './categorias'; | ||
|
||
const lienzo2 = document.getElementById('lienzo2') as HTMLCanvasElement; | ||
const lienzo3 = document.getElementById('lienzo3') as HTMLCanvasElement; | ||
const ctx3 = lienzo3.getContext('2d'); | ||
const listaCategorias = document.getElementById('listaCategorias') as HTMLDivElement; | ||
let categorias: { [categoria: string]: { contador: HTMLSpanElement; apariciones: Aparicion[] } } = {}; | ||
|
||
export default { | ||
reiniciar: () => { | ||
listaCategorias.innerHTML = ''; | ||
categorias = {}; | ||
}, | ||
|
||
agregar: (nombreCategoria: string, confianza: number, area: Cuadro, tiempo: number) => { | ||
const categoria = categorias[nombreCategoria]; | ||
|
||
if (!categoria) { | ||
const elemento = document.createElement('div'); | ||
const contador = document.createElement('span'); | ||
const barra = document.createElement('span'); | ||
const color = categoriasConColor[nombreCategoria]; | ||
|
||
elemento.className = 'categoria'; | ||
elemento.innerText = nombreCategoria; | ||
contador.className = 'contadorCategoria'; | ||
contador.innerText = '1'; | ||
barra.className = 'barraColor'; | ||
barra.style.backgroundColor = color; | ||
|
||
elemento.appendChild(barra); | ||
elemento.appendChild(contador); | ||
listaCategorias.appendChild(elemento); | ||
|
||
elemento.onclick = () => { | ||
console.log(`Apariciones de categoría ${nombreCategoria}`, categorias[nombreCategoria].apariciones); | ||
}; | ||
|
||
elemento.onmouseenter = () => { | ||
if (!ctx3) return; | ||
|
||
lienzo2.classList.remove('visible'); | ||
lienzo3.classList.add('visible'); | ||
|
||
ctx3.clearRect(0, 0, lienzo3.width, lienzo3.height); | ||
|
||
const { apariciones } = categorias[nombreCategoria]; | ||
|
||
if (apariciones && apariciones.length) { | ||
ctx3.fillStyle = color; | ||
ctx3.globalAlpha = 0.05; | ||
|
||
apariciones.forEach(({ area }) => { | ||
ctx3.fillRect(area.x, area.y, area.alto, area.alto); | ||
}); | ||
} | ||
}; | ||
|
||
elemento.onmouseleave = () => { | ||
lienzo2.classList.add('visible'); | ||
lienzo3.classList.remove('visible'); | ||
}; | ||
|
||
categorias[nombreCategoria] = { contador, apariciones: [] }; | ||
} else { | ||
categoria.contador.innerText = `${categoria.apariciones.length + 1}`; | ||
} | ||
|
||
categorias[nombreCategoria].apariciones.push({ tiempo, area, confianza }); | ||
}, | ||
|
||
apariciones: () => { | ||
return categorias.apariciones; | ||
}, | ||
}; | ||
export default function utilidadPredicciones( | ||
lienzoEspectros: HTMLCanvasElement, | ||
lienzoEspectroCategoria: HTMLCanvasElement | ||
) { | ||
const ctx3 = lienzoEspectroCategoria.getContext('2d'); | ||
|
||
return { | ||
reiniciar: () => { | ||
listaCategorias.innerHTML = ''; | ||
categorias = {}; | ||
}, | ||
|
||
agregar: (nombreCategoria: string, confianza: number, area: Cuadro, tiempo: number) => { | ||
const categoria = categorias[nombreCategoria]; | ||
|
||
if (!categoria) { | ||
const elemento = document.createElement('div'); | ||
const contador = document.createElement('span'); | ||
const barra = document.createElement('span'); | ||
const color = categoriasConColor[nombreCategoria]; | ||
|
||
elemento.className = 'categoria'; | ||
elemento.innerText = nombreCategoria; | ||
contador.className = 'contadorCategoria'; | ||
contador.innerText = '1'; | ||
barra.className = 'barraColor'; | ||
barra.style.backgroundColor = color; | ||
|
||
elemento.appendChild(barra); | ||
elemento.appendChild(contador); | ||
listaCategorias.appendChild(elemento); | ||
|
||
elemento.onclick = () => { | ||
console.log(`Apariciones de categoría ${nombreCategoria}`, categorias[nombreCategoria].apariciones); | ||
}; | ||
|
||
elemento.onmouseenter = () => { | ||
if (!ctx3) return; | ||
|
||
lienzoEspectros.classList.remove('visible'); | ||
lienzoEspectroCategoria.classList.add('visible'); | ||
|
||
ctx3.clearRect(0, 0, lienzoEspectroCategoria.width, lienzoEspectroCategoria.height); | ||
|
||
const { apariciones } = categorias[nombreCategoria]; | ||
|
||
if (apariciones && apariciones.length) { | ||
ctx3.fillStyle = color; | ||
ctx3.globalAlpha = 0.05; | ||
|
||
apariciones.forEach(({ area }) => { | ||
ctx3.fillRect(area.x, area.y, area.alto, area.alto); | ||
}); | ||
} | ||
}; | ||
|
||
elemento.onmouseleave = () => { | ||
lienzoEspectros.classList.add('visible'); | ||
lienzoEspectroCategoria.classList.remove('visible'); | ||
}; | ||
|
||
categorias[nombreCategoria] = { contador, apariciones: [] }; | ||
} else { | ||
categoria.contador.innerText = `${categoria.apariciones.length + 1}`; | ||
} | ||
|
||
categorias[nombreCategoria].apariciones.push({ tiempo, area, confianza }); | ||
}, | ||
|
||
apariciones: () => { | ||
return categorias.apariciones; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters