Skip to content

Commit

Permalink
📈 Nueva interfaz y opción de visualizar apariciones
Browse files Browse the repository at this point in the history
  • Loading branch information
1cgonza committed Sep 23, 2024
1 parent 5392cb1 commit 8bbaa31
Show file tree
Hide file tree
Showing 10 changed files with 967 additions and 366 deletions.
24 changes: 16 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@
></script>
</head>
<body>
<div id="menu"></div>

<main id="contenedor">
<div id="controles">
<div id="mensaje"></div>
<ul id="listaVideos"></ul>
</div>

<div id="seccionVideo">
<canvas id="lienzo"></canvas>
<video id="video" autoplay controls></video>
<canvas id="lienzo1" class="lienzo visible"></canvas>
<canvas id="lienzo2" class="lienzo visible"></canvas>
<canvas id="lienzo3" class="lienzo"></canvas>

<video id="video" class="visible" autoplay controls></video>
<button id="iconoFullScreen">Full screen</button>
<div id="configuracionConfianza">
<p>Confidence level: <span id="valorConfianza"></span></p>
Expand All @@ -72,15 +77,18 @@
confidence detects less "objects" but the model has more confidence it is detecting the correct object. The
default is 50% - just in the middle of confidence and ability to detect.
</p>
<input id="downloadbutton" type="button" value="Download Result" />
<input id="descargar" type="button" value="Download Data" />
</div>
</div>

<div id="categorias">
<div class="columnas">
<span id="verVideo" class="modo activo">Video</span>
<span id="verVis" class="modo activo">Heatmap</span>
</div>

<div id="listaCategorias"></div>
</div>
<!-- <canvas id="lienzo2"></canvas>
<div id="otraInfo">
<div id="tiemposAparicionCategorias"></div>
<div id="espacioAparicionCategorias"></div>
</div> -->
</main>

<script type="module" src="/src/programa.ts"></script>
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
},
"devDependencies": {
"autoprefixer": "^10.4.20",
"cssnano": "^7.0.5",
"postcss": "^8.4.45",
"cssnano": "^7.0.6",
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"sass": "^1.78.0",
"sass": "^1.79.3",
"typescript": "^5.5.4",
"vite": "^5.4.3"
"vite": "^5.4.7"
},
"dependencies": {
"@mediapipe/tasks-vision": "^0.10.16",
"@tensorflow-models/coco-ssd": "^2.2.3",
"@tensorflow/tfjs": "^4.21.0",
"@tensorflow/tfjs-backend-cpu": "^4.21.0",
Expand Down
92 changes: 92 additions & 0 deletions src/componentes/categorias.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import coloresAMil from '../utilidades/colores';

const categorias = [
'person',
'bicycle',
'car',
'motorcycle',
'airplane',
'bus',
'train',
'truck',
'boat',
'traffic light',
'fire hydrant',
'stop sign',
'parking meter',
'bench',
'bird',
'cat',
'dog',
'horse',
'sheep',
'cow',
'elephant',
'bear',
'zebra',
'giraffe',
'backpack',
'umbrella',
'handbag',
'tie',
'suitcase',
'frisbee',
'skis',
'snowboard',
'sports ball',
'kite',
'baseball bat',
'baseball glove',
'skateboard',
'surfboard',
'tennis racket',
'bottle',
'wine glass',
'cup',
'fork',
'knife',
'spoon',
'bowl',
'banana',
'apple',
'sandwich',
'orange',
'broccoli',
'carrot',
'hot dog',
'pizza',
'donut',
'cake',
'chair',
'couch',
'potted plant',
'bed',
'dining table',
'toilet',
'tv',
'laptop',
'mouse',
'remote',
'keyboard',
'cell phone',
'microwave',
'oven',
'toaster',
'sink',
'refrigerator',
'book',
'clock',
'vase',
'scissors',
'teddy bear',
'hair drier',
'toothbrush',
];

const categoriasConColor: { [nombre: string]: string } = {};

categorias.forEach((categoria, i) => {
categoriasConColor[categoria] = coloresAMil[i];
});

export default categoriasConColor;
77 changes: 77 additions & 0 deletions src/componentes/predicciones.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { Aparicion, Cuadro } from '../tipos';
import categoriasConColor from './categorias';

const video = document.getElementById('video') as HTMLVideoElement;
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;
},
};
Loading

0 comments on commit 8bbaa31

Please sign in to comment.