3#include "../_cexports/c_polimago.h"
5#include "../global.hpp"
6#include "../string.hpp"
7#include "predictor_base.hpp"
8#include "classification_result.hpp"
47 class ClassificationPredictor :
public PredictorBaseEx
51 explicit ClassificationPredictor(ReleaseObjectGuard &&guard)
54 if (TrainingParameters().Usage == CExports::TClassifierUsage::CU_Regression)
60 for (
int i = 0; i < numClasses; ++i)
63 CVB_CALL_CAPI_CHECKED(PMGetClfClassLabelTyped(
Handle(), i, lbl.data()));
64 classes_.push_back(lbl.data());
69 static CExports::TCLF LoadInternal(
const String &fileName)
71 CExports::TCLF predictor =
nullptr;
73 CVB_CALL_CAPI_CHECKED(PMOpenClfTyped(fileName.c_str(), predictor));
77 void SaveFunction(
const String &fileName)
const override
79 CVB_CALL_CAPI_CHECKED(PMSaveClfTyped(fileName.c_str(),
Handle()));
84 return thisObjectName_;
94 : ClassificationPredictor(ReleaseObjectGuard(LoadInternal(fileName)))
124 return std::make_unique<ClassificationPredictor>(fileName);
144 if (TrainingParameters().Usage == CExports::TClassifierUsage::CU_ClassifyOneVersusAll)
148 else if (TrainingParameters().Usage == CExports::TClassifierUsage::CU_ClassifyOneVersusOne)
165 return CVB_CALL_CAPI(PMGetOutputDimension(
Handle()));
175 return static_cast<int>(CVB_CALL_CAPI(PMGetNumClasses(
Handle())));
188 VerifyCompatibility(img, pos);
191 double confidence = 0.0;
193 CVB_CALL_CAPI_CHECKED(PMClassifyTyped(
Handle(), img.Handle(), pos.
X(), pos.
Y(), lbl.data(), classNameMaxLength_,
194 confidence, confidences.data()));
209 return Classify(img, pos, confidences);
214 static const int classNameMaxLength_ = 256;
215 const std::string thisObjectName_ =
"Polimago Classification Predictor";
47 class ClassificationPredictor :
public PredictorBaseEx {
…};
The Common Vision Blox image.
Definition decl_image.hpp:45
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
int NumClasses() const
Number of classes a classification predictor has been trained for.
Definition classification_predictor.hpp:173
static std::unique_ptr< ClassificationPredictor > FromHandle(ReleaseObjectGuard &&guard)
Creates predictor from a classic API handle.
Definition classification_predictor.hpp:107
static std::unique_ptr< ClassificationPredictor > Load(const String &fileName)
Load a saved predictor from a file.
Definition classification_predictor.hpp:122
ClassificationResult Classify(const Image &img, Point2D< int > pos)
Classify a location inside an image.
Definition classification_predictor.hpp:206
ClassificationPredictor(const String &fileName)
Load a saved Polimago classification predictor from a file.
Definition classification_predictor.hpp:93
int OutputDimension() const
Dimension of results generated by this predictor.
Definition classification_predictor.hpp:163
std::vector< String > Classes() const
Class labels available in this predictor.
Definition classification_predictor.hpp:132
ClassificationType Classification() const
The classification type for which this classifier has been generated.
Definition classification_predictor.hpp:142
ClassificationResult Classify(const Image &img, Point2D< int > pos, std::vector< double > &confidences)
Classify a location inside an image.
Definition classification_predictor.hpp:186
Polimago classification result container.
Definition classification_result.hpp:20
void * Handle() const noexcept
Classic API Polimago handle.
Definition predictor_base.hpp:68
Namespace for the Polimago package.
Definition classification_predictor.hpp:29
std::shared_ptr< ClassificationPredictor > ClassificationPredictorPtr
Convenience shared pointer for ClassificationPredictor.
Definition classification_predictor.hpp:219
ClassificationType
Determine the classification type to be carried out.
Definition classification_predictor.hpp:33
@ None
The enum element indicating undefined state.
Definition classification_predictor.hpp:35
@ OneVersusAll
Definition classification_predictor.hpp:38
@ OneVersusOne
Definition classification_predictor.hpp:41
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49