Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

345
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda