Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

346
Vistas
TypeError: Cannot read properties of undefined (reading 'color')

I am trying to work on a Facemask Detection System. I have trained the Images and I have my model. I have also converted the generated model to the TensorflowJS json file.

I am having a problem implementing the tfjs model via a REACT application. I have my model being loaded successfully. As I have console.log it but i am having some issues drawing the rectangular bounding boxes for the detected class. The browser is throwing an error TypeError: Cannot read properties of undefined (reading 'color').

Here is my utilities.js file which is throwing the error.

// Define our labelmap
const labelMap = [
  {id: 1, name:'with mask', color:'red'},
  {id: 2, name:'no mask', color:'yellow'},
  {id: 3, name:'incorrect', color:'lime'},
]

// Define a drawing function
export const drawRect = (boxes, classes, scores, threshold, imgWidth, imgHeight, ctx)=>{
  for(let i=0; i<=boxes.length; i++){
      if(boxes[i] && classes[i] && scores[i]>threshold){
          // Extract variables
          const [y,x,height,width] = boxes[i]
          const text = classes[i]
          
          // Set styling
          ctx.strokeStyle = labelMap[text]["color"]
          ctx.lineWidth = 10
          ctx.fillStyle = 'white'
          ctx.font = '30px Arial'         
          
          // DRAW!!
          ctx.beginPath()
          ctx.fillText(labelMap[text]['name'] + ' - ' + Math.round(scores[i]*100)/100, x*imgWidth, y*imgHeight-10)
          ctx.rect(x*imgWidth, y*imgHeight, width*imgWidth/2, height*imgHeight/2);
          ctx.stroke()
      }
  }
}

I know this error has to do with the way the labelMap color variable is referenced. It is throwing the error probably because i am not referencing the color variable well. Also if this error is fixed. I will also be having another error thrown in labelMap[text]['name'] because the referencing is done same way.

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda