3#include "../_cexports/c_polimago.h"
5#include "../global.hpp"
6#include "../value_range.hpp"
8#include "predictor_base.hpp"
9#include "search_result.hpp"
35namespace Training {
class SearchPredictorFactory; }
46 , maxNumResults_(maxNumResultsDefault_)
48 CVB_CALL_CAPI (PMGetSearchClfTrainParams (
Handle (), TrainingParameters(), searchTrainingParameters_));
52 void InitResultBuffer()
54 pbuffer_.assign (
MaxNumResults (), CExports::TSearchResult ());
58 static CExports::TSCLF LoadInternal (
const String & fileName)
60 CExports::TSCLF predictor =
nullptr;
62 CVB_CALL_CAPI_CHECKED (PMOpenSearchClfTyped(fileName.c_str(), predictor));
66 void SaveFunction (
const String &fileName)
const override
68 CVB_CALL_CAPI_CHECKED (PMSaveSearchClfTyped(fileName.c_str(),
Handle()));
73 return thisObjectName_;
113 return std::make_unique<SearchPredictor>(fileName);
123 return maxNumResults_;
133 if (maxNumResults == maxNumResults_)
137 if (maxNumResults < 1)
141 maxNumResults_ = maxNumResults;
152 return searchTrainingParameters_.SampleSize;
169 return searchTrainingParameters_.InvarianceParams.XYRadius;
190 return ValueRange<double>(searchTrainingParameters_.InvarianceParams.MinScaleMinL, searchTrainingParameters_.InvarianceParams.MaxScaleMaxL);
200 return static_cast<InvarianceType>(searchTrainingParameters_.InvarianceParams.InvarianceType);
210 return searchTrainingParameters_.NumClfs;
220 return searchTrainingParameters_.Resolution12;
230 return searchTrainingParameters_.ResolutionRest;
251 VerifyCompatibility(img);
253 CExports::cvbval_t numCallsOut = 0;
254 auto resultCount = CVB_CALL_CAPI (PMGridSearch(
Handle(), img.Handle(), aoi.Left(), aoi.Top(), aoi.Right(), aoi.Bottom(), gridStep, threshold, locality, maxNumResults_, &pbuffer_[0], numCallsOut));
255 numCalls =
static_cast<int>(numCallsOut);
258 for (
decltype(resultCount) i = 0; i < resultCount; ++i)
283 return GridSearch (img, aoi, gridStep, threshold, locality, numCalls);
301 VerifyCompatibility(img);
302 CExports::TSearchResult tmpRes = res.resInternal_;
303 CExports::cvbval_t tmpDepth = searchDepth;
305 auto retval = CVB_CALL_CAPI(PMInspect(
Handle(), img.Handle(), tmpRes, tmpDepth));
309 searchDepth =
static_cast<int>(tmpDepth);
330 VerifyCompatibility(img);
331 CExports::TSearchResult tmpRes = res.resInternal_;
332 CExports::cvbval_t tmpDepth = searchDepth;
333 CExports::TDiagnostics diag = {};
335 auto retval = CVB_CALL_CAPI(PMInspectD(
Handle(), img.Handle(), tmpRes, tmpDepth, diag));
339 searchDepth =
static_cast<int>(tmpDepth);
343 for (
int i = 0; i < searchDepth; ++i)
361 return Internal::DoBoolCallObjectOut<Image>([&](
void* & resimg)
363 return CVB_CALL_CAPI(PMSearchResultToImage(
Handle(), sourceImage.
Handle(), res.resInternal_.G, resimg));
372 static const int maxNumResultsDefault_ = 4096;
373 const std::string thisObjectName_ =
"Polimago Search Predictor";
374 CExports::TTrainSearchParams searchTrainingParameters_;
375 CExports::cvbval_t maxNumResults_;
static Angle FromRadians(double rad, bool trim=false) noexcept
Create an angle in radians.
Definition: angle.hpp:44
The Common Vision Blox image.
Definition: decl_image.hpp:45
void * Handle() const noexcept
Classic API image handle.
Definition: decl_image.hpp:226
void * Handle() const noexcept
Classic API Polimago handle.
Definition: predictor_base.hpp:69
Base class for Polimago predictors.
Definition: predictor_base.hpp:212
Predictor that may be used for searching objects.
Definition: search_predictor.hpp:41
int NumClassificationSteps() const noexcept
Get the number of classification steps defined during training.
Definition: search_predictor.hpp:208
SearchPredictor(const String &fileName)
Load a saved Polimago search predictor from a file.
Definition: search_predictor.hpp:82
std::unique_ptr< Image > SearchResultToImage(const Image &sourceImage, SearchResult res)
Create a visual representation of a search result.
Definition: search_predictor.hpp:359
ValueRange< double > ScaleRange() const noexcept
Get the range of scale factors that was covered during classifier training.
Definition: search_predictor.hpp:188
int MaxNumResults() const noexcept
Get the maximum number of results that can be extracted in a GridSearch operation.
Definition: search_predictor.hpp:121
bool Inspect(const Image &img, SearchResult &res, int &searchDepth)
Carries out the operation that GridSearch executes for a grid point, starting at the perspective and ...
Definition: search_predictor.hpp:299
double ExtractionRadius() const noexcept
Get the radius for extracting positive search instances.
Definition: search_predictor.hpp:167
std::vector< SearchResult > GridSearch(const Image &img, Rect< int > aoi, double gridStep, double threshold, double locality)
Perform a grid search.
Definition: search_predictor.hpp:280
int FeatureResolutionStep1And2() const noexcept
Get the feature resolution to be used for the first two classification steps.
Definition: search_predictor.hpp:218
std::vector< SearchResult > GridSearch(const Image &img, Rect< int > aoi, double gridStep, double threshold, double locality, int &numCalls)
Perform a grid search.
Definition: search_predictor.hpp:249
static std::unique_ptr< SearchPredictor > Load(const String &fileName)
Load a saved predictor from a file.
Definition: search_predictor.hpp:111
static std::unique_ptr< SearchPredictor > FromHandle(ReleaseObjectGuard &&guard)
Creates predictor from a classic API handle.
Definition: search_predictor.hpp:96
bool Inspect(const Image &img, SearchResult &res, int &searchDepth, std::vector< SearchResult > &trace)
Carries out the operation that GridSearch executes for a grid point, starting at the perspective and ...
Definition: search_predictor.hpp:328
ValueRange< Angle > RotationRange() const noexcept
Get the range of angles that was covered during classifier training.
Definition: search_predictor.hpp:177
void SetMaxNumResults(int maxNumResults)
Set the maximum number of results that can be extracted in a GridSearch operation....
Definition: search_predictor.hpp:131
int FeatureResolutionRest() const noexcept
Get the feature resolution to be used for the third and later classification steps.
Definition: search_predictor.hpp:228
int SampleSize() const noexcept
Get the sample size that has been used in each training set.
Definition: search_predictor.hpp:150
InvarianceType Invariances() const noexcept
Get the invariances that have been trained on this classifier.
Definition: search_predictor.hpp:198
Search results as provided by a Search Classifier.
Definition: search_result.hpp:21
Factory class for the generation of search predictors.
Definition: search_predictor_factory.hpp:30
Container for range definitions.
Definition: value_range.hpp:17
InvarianceType
Invariance types that can be defined for training.
Definition: search_predictor.hpp:23
@ AffineGroup
Affine group (i.e. 2x2 matrix plus translation).
@ Translation
Translation.
@ RotationScaleTranslation
Rotation + Scale + Translation.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24