mirror of
https://github.com/dgirardeau/q3DMASC.git
synced 2026-08-30 00:50:49 +08:00
Classifiers can be saved and loaded
This commit is contained in:
+24
-10
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user