LCOV - code coverage report
Current view: top level - sources/objectDetection - LabelManager.cpp (source / functions) Hit Total Coverage
Test: filtered.info Lines: 21 21 100.0 %
Date: 2025-08-07 15:31:19 Functions: 4 4 100.0 %

          Line data    Source code
       1             : #include "../../includes/objectDetection/LabelManager.hpp"
       2             : 
       3             : /**
       4             :  * @brief Construtor que carrega as labels de um arquivo.
       5             :  * @param labelPath Caminho para o arquivo de labels.
       6             :  */
       7           5 : LabelManager::LabelManager(const std::string& labelPath) {
       8           5 :         loadLabels(labelPath);
       9           5 : }
      10             : 
      11             : /**
      12             :  * @brief Carrega as labels do arquivo especificado.
      13             :  * @param labelPath Caminho para o arquivo de labels.
      14             :  */
      15           5 : void LabelManager::loadLabels(const std::string& labelPath) {
      16           5 :         std::ifstream file(labelPath);
      17           5 :         if (!file.is_open()) {
      18           2 :                 std::cerr << "[ERRO] Não foi possível abrir o arquivo de labels: " << labelPath << std::endl;
      19           2 :                 return;
      20             :         }
      21             : 
      22           6 :         std::string line;
      23           8 :         while (std::getline(file, line)) {
      24           5 :                 line.erase(0, line.find_first_not_of(" \t\r\n"));
      25           5 :                 line.erase(line.find_last_not_of(" \t\r\n") + 1);
      26           5 :                 labels.push_back(line);
      27             :         }
      28           3 :         file.close();
      29             : 
      30           3 :         std::cout << "[INFO] Carregadas " << labels.size() << " labels." << std::endl;
      31             : }
      32             : 
      33             : /**
      34             :  * @brief Retorna o nome da label para um dado classId.
      35             :  * @param classId Índice da classe.
      36             :  * @return Nome da classe ou "Unknown".
      37             :  */
      38           7 : std::string LabelManager::getLabel(int classId) const {
      39             :         // Correção: cast para evitar warning signed/unsigned
      40           7 :         if (classId >= 0 && static_cast<size_t>(classId) < labels.size()) {
      41           3 :                 return labels[classId];
      42             :         }
      43           4 :         return "Unknown";
      44             : }
      45             : 
      46             : /**
      47             :  * @brief Retorna o número de classes carregadas.
      48             :  * @return Número de classes.
      49             :  */
      50           3 : size_t LabelManager::getNumClasses() const {
      51           3 :         return labels.size();
      52             : }

Generated by: LCOV version 1.14