ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
q3DMASCClassifier.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 // ##########################################################################
11 // # #
12 // # ACLOUDVIEWER PLUGIN: q3DMASC #
13 // # #
14 // # This program is free software; you can redistribute it and/or modify #
15 // # it under the terms of the GNU General Public License as published by #
16 // # the Free Software Foundation; version 2 or later of the License. #
17 // # #
18 // # This program is distributed in the hope that it will be useful, #
19 // # but WITHOUT ANY WARRANTY; without even the implied warranty of #
20 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
21 // # GNU General Public License for more details. #
22 // # #
23 // # COPYRIGHT: Dimitri Lague / CNRS / UEB #
24 // # #
25 // ##########################################################################
26 
27 // Local
28 #include "FeaturesInterface.h"
29 #include "Parameters.h"
30 
31 // Qt
32 #include <QString>
33 
34 // CCLib
35 #include <ReferenceCloud.h>
36 
37 // OpenCV
38 #include <opencv2/ml.hpp>
39 
40 class QWidget;
42 class ConfusionMatrix;
43 class Train3DMASCDialog;
44 
46 namespace masc {
47 class Classifier {
48 public:
50  Classifier();
51 
53  bool train(const ccPointCloud* cloud,
55  const Feature::Source::Set& featureSources,
56  QString& errorMessage,
57  cloudViewer::ReferenceCloud* trainSubset = nullptr,
58  ecvMainAppInterface* app = nullptr,
59  QWidget* parentWidget = nullptr);
60 
62  struct AccuracyMetrics {
63  unsigned sampleCount = 0;
64  unsigned goodGuess = 0;
65  float ratio = 0.0f;
66  };
67 
69  bool evaluate(const Feature::Source::Set& featureSources,
70  ccPointCloud* testCloud,
71  AccuracyMetrics& metrics,
72  QString& errorMessage,
73  Train3DMASCDialog& train3DMASCDialog,
74  cloudViewer::ReferenceCloud* testSubset = nullptr,
75  QString outputSFName = QString(),
76  QWidget* parentWidget = nullptr,
77  ecvMainAppInterface* app = nullptr);
78 
80  bool classify(const Feature::Source::Set& featureSources,
81  ccPointCloud* cloud,
82  QString& errorMessage,
83  QWidget* parentWidget = nullptr,
84  ecvMainAppInterface* app = nullptr);
85 
87  bool isValid() const;
88 
90  bool toFile(QString filename, QWidget* parentWidget = nullptr) const;
92  bool fromFile(QString filename, QWidget* parentWidget = nullptr);
93 
94  inline cv::Mat getVarImportance() const {
95  return m_rtrees->getVarImportance();
96  }
97 
98 protected:
100  cv::Ptr<cv::ml::RTrees> m_rtrees;
101 };
102 
103 }; // namespace masc
std::string filename
cmdLineReadable * params[]
3DMASC plugin 'train' dialog
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
A very simple point cloud (no point duplication)
Main application interface (for plugins)
bool toFile(QString filename, QWidget *parentWidget=nullptr) const
Saves the classifier to file.
bool isValid() const
Returns whether the classifier is valid or not.
bool evaluate(const Feature::Source::Set &featureSources, ccPointCloud *testCloud, AccuracyMetrics &metrics, QString &errorMessage, Train3DMASCDialog &train3DMASCDialog, cloudViewer::ReferenceCloud *testSubset=nullptr, QString outputSFName=QString(), QWidget *parentWidget=nullptr, ecvMainAppInterface *app=nullptr)
Evaluates the classifier.
bool classify(const Feature::Source::Set &featureSources, ccPointCloud *cloud, QString &errorMessage, QWidget *parentWidget=nullptr, ecvMainAppInterface *app=nullptr)
Applies the classifier.
cv::Mat getVarImportance() const
bool train(const ccPointCloud *cloud, const RandomTreesParams &params, const Feature::Source::Set &featureSources, QString &errorMessage, cloudViewer::ReferenceCloud *trainSubset=nullptr, ecvMainAppInterface *app=nullptr, QWidget *parentWidget=nullptr)
Train the classifier.
bool fromFile(QString filename, QWidget *parentWidget=nullptr)
Loads the classifier from file.
cv::Ptr< cv::ml::RTrees > m_rtrees
Random trees (OpenCV)
Classifier()
Default constructor.
3DMASC classifier
Classifier accuracy metrics.
std::vector< Source > Set