3#include "../_cexports/c_polimago.h"
5#include "../global.hpp"
6#include "../string.hpp"
7#include "predictor_base.hpp"
8#include "classification_result.hpp"
51 if (TrainingParameters().Usage == CExports::TClassifierUsage::CU_Regression)
57 for (
int i = 0; i < numClasses; ++i)
60 CVB_CALL_CAPI_CHECKED(PMGetClfClassLabelTyped(
Handle(), i, lbl.data()));
61 classes_.push_back (lbl.data());
66 static CExports::TCLF LoadInternal (
const String & fileName)
68 CExports::TCLF predictor =
nullptr;
70 CVB_CALL_CAPI_CHECKED (PMOpenClfTyped(fileName.c_str(), predictor));
74 void SaveFunction (
const String &fileName)
const override
76 CVB_CALL_CAPI_CHECKED (PMSaveClfTyped(fileName.c_str(),
Handle()));
81 return thisObjectName_;
107 if (!guard.Handle ())
122 return std::make_unique<ClassificationPredictor>(fileName);
143 if (TrainingParameters().Usage == CExports::TClassifierUsage::CU_ClassifyOneVersusAll)
147 else if (TrainingParameters().Usage == CExports::TClassifierUsage::CU_ClassifyOneVersusOne)
164 return CVB_CALL_CAPI(PMGetOutputDimension(
Handle()));
174 return static_cast<int>(CVB_CALL_CAPI(PMGetNumClasses(
Handle())));
187 VerifyCompatibility(img, pos);
190 double confidence = 0.0;
192 CVB_CALL_CAPI_CHECKED(PMClassifyTyped(
Handle(), img.Handle(), pos.
X(), pos.
Y(), lbl.data(), classNameMaxLength_, confidence, confidences.data()));
207 return Classify (img, pos, confidences);
212 static const int classNameMaxLength_ = 256;
213 const std::string thisObjectName_ =
"Polimago Classification Predictor";
The Common Vision Blox image.
Definition: decl_image.hpp:45
T X() const noexcept
Gets the x-component of the point.
Definition: point_2d.hpp:86
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:106
Predictor to classify patterns with.
Definition: classification_predictor.hpp:45
int NumClasses() const
Number of classes a classification predictor has been trained for.
Definition: classification_predictor.hpp:172
static std::unique_ptr< ClassificationPredictor > FromHandle(ReleaseObjectGuard &&guard)
Creates predictor from a classic API handle.
Definition: classification_predictor.hpp:105
static std::unique_ptr< ClassificationPredictor > Load(const String &fileName)
Load a saved predictor from a file.
Definition: classification_predictor.hpp:120
ClassificationResult Classify(const Image &img, Point2D< int > pos)
Classify a location inside an image.
Definition: classification_predictor.hpp:204
ClassificationPredictor(const String &fileName)
Load a saved Polimago classification predictor from a file.
Definition: classification_predictor.hpp:90
int OutputDimension() const
Dimension of results generated by this predictor.
Definition: classification_predictor.hpp:162
std::vector< String > Classes() const
Class labels available in this predictor.
Definition: classification_predictor.hpp:131
ClassificationType Classification() const
The classification type for which this classifier has been generated.
Definition: classification_predictor.hpp:141
ClassificationResult Classify(const Image &img, Point2D< int > pos, std::vector< double > &confidences)
Classify a location inside an image.
Definition: classification_predictor.hpp:185
Polimago classification result container.
Definition: classification_result.hpp:20
void * Handle() const noexcept
Classic API Polimago handle.
Definition: predictor_base.hpp:69
Base class for Polimago predictors.
Definition: predictor_base.hpp:293
ClassificationType
Determine the classification type to be carried out.
Definition: classification_predictor.hpp:32
@ OneVersusAll
Quick classification, that tests versus all classes simultaneously (but potentially at the cost of re...
@ OneVersusOne
Thorough classification, that tests all possible pairs of classes (which yields potentially better re...
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24