Classifiers can be saved and loaded

This commit is contained in:
Daniel Girardeau-Montaut
2018-10-26 10:46:35 +02:00
parent d405332370
commit 65e5bfd35d
2 changed files with 25 additions and 11 deletions
+24 -10
View File
@@ -134,17 +134,31 @@ void q3DMASCPlugin::doTrainAction()
features.push_back(Feature::Shared(new PointFeature(cloud, PointFeature::Intensity, Feature::ScalarField, "Intensity")));
}
masc::Classifier classifier;
QString errorMessage;
if (!classifier.train(params, features, errorMessage, m_app->getMainWindow()))
{
m_app->dispToConsole(errorMessage);
return;
}
//save the classifier
QString outputFilename = QCoreApplication::applicationDirPath() + "/classifier.yaml";
classifier.toFile(outputFilename, m_app->getMainWindow());
masc::Classifier classifier;
if (QFile(outputFilename).exists())
{
if (!classifier.fromFile(outputFilename, m_app->getMainWindow()))
{
m_app->dispToConsole("Failed to load previous classifier file", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
m_app->dispToConsole("Previous classifier loaded", ccMainAppInterface::WRN_CONSOLE_MESSAGE);
}
else
{
QString errorMessage;
if (!classifier.train(params, features, errorMessage, m_app->getMainWindow()))
{
m_app->dispToConsole(errorMessage, ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
//save the classifier
classifier.toFile(outputFilename, m_app->getMainWindow());
m_app->dispToConsole("Classifier succesfully created", ccMainAppInterface::WRN_CONSOLE_MESSAGE);
}
}
void q3DMASCPlugin::registerCommands(ccCommandLineInterface* cmd)
+1 -1
View File
@@ -328,7 +328,7 @@ bool Classifier::fromFile(QString filename, QWidget* parentWidget/*=nullptr*/)
//load the classifier
QProgressDialog pDlg(parentWidget);
pDlg.setRange(0, 0); //infinite loop
pDlg.setLabelText(QObject::tr("Saving classifier"));
pDlg.setLabelText(QObject::tr("Loading classifier"));
pDlg.show();
QCoreApplication::processEvents();