ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
confusionmatrix.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <CVTypes.h>
11 #include <ecvMainAppInterface.h>
12 
13 #include <QWidget>
14 #include <opencv2/core/mat.hpp>
15 #include <set>
16 
17 namespace Ui {
18 class ConfusionMatrix;
19 }
20 
21 class ConfusionMatrix : public QWidget {
22  Q_OBJECT
23 
24 public:
25  enum metrics { PRECISION = 0, RECALL = 1, F1_SCORE = 2 };
26 
27  explicit ConfusionMatrix(const std::vector<ScalarType>& actual,
28  const std::vector<ScalarType>& predicted);
29  ~ConfusionMatrix() override;
30 
31  void computePrecisionRecallF1Score(cv::Mat& matrix,
32  cv::Mat& precisionRecallF1Score,
33  cv::Mat& vec_TP_FN);
34  float computeOverallAccuracy(cv::Mat& matrix);
35  void compute(const std::vector<ScalarType>& actual,
36  const std::vector<ScalarType>& predicted);
37  void setSessionRun(QString session, int run);
38  bool save(QString filePath);
39  float getOverallAccuracy();
40 
41 private:
42  std::set<ScalarType> classes;
43  int nbClasses;
44  Ui::ConfusionMatrix* ui;
45  cv::Mat confusionMatrix;
46  cv::Mat precisionRecallF1Score;
47  std::vector<ScalarType> class_numbers;
48  float m_overallAccuracy;
49 };
~ConfusionMatrix() override
void computePrecisionRecallF1Score(cv::Mat &matrix, cv::Mat &precisionRecallF1Score, cv::Mat &vec_TP_FN)
void setSessionRun(QString session, int run)
void compute(const std::vector< ScalarType > &actual, const std::vector< ScalarType > &predicted)
ConfusionMatrix(const std::vector< ScalarType > &actual, const std::vector< ScalarType > &predicted)
bool save(QString filePath)
float computeOverallAccuracy(cv::Mat &matrix)