CVB++ 14.0
SearchPredictor Class Reference

Predictor that may be used for searching objects. More...

#include <cvb/polimago/search_predictor.hpp>

Inherits PredictorBase.

Public Member Functions

 SearchPredictor (const String &fileName)
 Load a saved Polimago search predictor from a file. More...
 
 SearchPredictor (SearchPredictor &&) noexcept=default
 Move constructor.
 
SearchPredictoroperator= (SearchPredictor &&) noexcept=default
 Move assignment operator.
 
int MaxNumResults () const noexcept
 Get the maximum number of results that can be extracted in a GridSearch operation. More...
 
void SetMaxNumResults (int maxNumResults)
 Set the maximum number of results that can be extracted in a GridSearch operation. Increasing this value will increase the amount of memory allocated by this SearchPredictor object. More...
 
int SampleSize () const noexcept
 Get the sample size that has been used in each training set. More...
 
double ExtractionRadius () const noexcept
 Get the radius for extracting positive search instances. More...
 
ValueRange< AngleRotationRange () const noexcept
 Get the range of angles that was covered during classifier training. More...
 
ValueRange< double > ScaleRange () const noexcept
 Get the range of scale factors that was covered during classifier training. More...
 
InvarianceType Invariances () const noexcept
 Get the invariances that have been trained on this classifier. More...
 
int NumClassificationSteps () const noexcept
 Get the number of classification steps defined during training. More...
 
int FeatureResolutionStep1And2 () const noexcept
 Get the feature resolution to be used for the first two classification steps. More...
 
int FeatureResolutionRest () const noexcept
 Get the feature resolution to be used for the third and later classification steps. More...
 
std::vector< SearchResultGridSearch (const Image &img, Rect< int > aoi, double gridStep, double threshold, double locality, int &numCalls)
 Perform a grid search. More...
 
std::vector< SearchResultGridSearch (const Image &img, Rect< int > aoi, double gridStep, double threshold, double locality)
 Perform a grid search. More...
 
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 position defined by the initial value of the parameter SearchResult. More...
 
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 position defined by the initial value of the parameter SearchResult. More...
 
std::unique_ptr< ImageSearchResultToImage (const Image &sourceImage, SearchResult res)
 Create a visual representation of a search result. More...
 
- Public Member Functions inherited from PredictorBase
bool IsCompatible (const Image &img, Point2D< int > pos) const
 Verify the compatibility of a CVB image with this classifier. More...
 
bool IsCompatible (const Image &img) const
 Verify the compatibility of a CVB image with this classifier. More...
 
- Public Member Functions inherited from PolimagoFactoryCreatedObject
void * Handle () const noexcept
 Classic API Polimago handle. More...
 
String FileName () const
 Name of the file the object has been loaded from (or empty string if the object was not loaded). More...
 
void Save (const String &fileName) const
 Save this object into a file. More...
 
double Lambda () const noexcept
 Regularization value that has been used for generating this object. More...
 
double Offset () const noexcept
 Intercept weight that has been used for generating this object. More...
 
InterpolationType Interpolation () const noexcept
 Interpolation setting used for generating this object. More...
 
int ImagePlanes () const noexcept
 The plane count of the images that have been used for generating this classifier. Image on which this classifier is to be used will need to have the same plane count. More...
 
Rect< int > FeatureWindowExtent () const noexcept
 The feature window extent that has been used during classifier training. More...
 
Size2D< int > RetinaSize () const noexcept
 Size of the 'Retina' in pixels. The retina is the set of paxels onto which the input image is projected using the preprocessing code prior to application/training of the classifier. More...
 
Point2D< double > Correction () const noexcept
 Correction factors in X and Y direction required to rescale the input images for projection onto the retina. More...
 
String Preprocessing () const
 Preprocessing code with which this object was generated. More...
 

Static Public Member Functions

static std::unique_ptr< SearchPredictorFromHandle (ReleaseObjectGuard &&guard)
 Creates predictor from a classic API handle. More...
 
static std::unique_ptr< SearchPredictorLoad (const String &fileName)
 Load a saved predictor from a file. More...
 

Detailed Description

Predictor that may be used for searching objects.

Constructor & Destructor Documentation

◆ SearchPredictor()

SearchPredictor ( const String fileName)
inline

Load a saved Polimago search predictor from a file.

Parameters
[in]fileNameName of the file to be loaded.
Returns
Loaded predictor.
Exceptions
Anyexception derived from std::exception including CvbException.

Member Function Documentation

◆ ExtractionRadius()

double ExtractionRadius ( ) const
inlinenoexcept

Get the radius for extracting positive search instances.

Returns
Extraction radius.
Exceptions
Doesnot throw any exception.

The unit size is the size of the feature window, i.e. a value of 0.5 means that positive samples can be extracted from withing a range of +/- Feature Window Width and +/- Feature Window Height around each trained instance. Smaller values will necessitate a finer search grid but may yield better results on difficult search tasks.

◆ FeatureResolutionRest()

int FeatureResolutionRest ( ) const
inlinenoexcept

Get the feature resolution to be used for the third and later classification steps.

Returns
Feature resolution.
Exceptions
Doesnot throw any exception.

◆ FeatureResolutionStep1And2()

int FeatureResolutionStep1And2 ( ) const
inlinenoexcept

Get the feature resolution to be used for the first two classification steps.

Returns
Feature resolution.
Exceptions
Doesnot throw any exception.

◆ FromHandle()

static std::unique_ptr< SearchPredictor > FromHandle ( ReleaseObjectGuard &&  guard)
inlinestatic

Creates predictor from a classic API handle.

Parameters
[in]guardLife time guard for C-API handle.
Returns
The predictor created from the classic API handle.
Exceptions
Anyexception derived from std::exception including CvbException.

The predictor takes ownership of the handle, so you must share it before using this function.

◆ GridSearch() [1/2]

std::vector< SearchResult > GridSearch ( const Image img,
Rect< int >  aoi,
double  gridStep,
double  threshold,
double  locality 
)
inline

Perform a grid search.

Parameters
[in]imgImage to search in.
[in]aoiAOI inside the image to search in.
[in]gridStepSpacing of the grid points in units of the feature window width/height.
[in]thresholdMinimum quality a result must have for being reported.
[in]localityMinimum distance between the results that this SearchPredictor found.
Returns
List of results that this SearchPredictor found in the area of interest.
Exceptions
Anyexception derived from std::exception including CvbException.

If two results that exceed the quality requirement defined by the threshold parameter are spaced less than 'locality' pixels apart (in either x or y direction) then the result with the lower quality will be eliminated from the result list.

◆ GridSearch() [2/2]

std::vector< SearchResult > GridSearch ( const Image img,
Rect< int >  aoi,
double  gridStep,
double  threshold,
double  locality,
int &  numCalls 
)
inline

Perform a grid search.

Parameters
[in]imgImage to search in.
[in]aoiAOI inside the image to search in.
[in]gridStepSpacing of the grid points in units of the feature window width/height.
[in]thresholdMinimum quality a result must have for being reported.
[in]localityMinimum distance between the results that this SearchPredictor found.
[out]numCallsWill receive the number of calls to the predictor's classification routine that have been carried out in the GridSearch call (output).
Returns
List of results that this SearchPredictor found in the area of interest.
Exceptions
Anyexception derived from std::exception including CvbException.

If two results that exceed the quality requirement defined by the threshold parameter are spaced less than 'locality' pixels apart (in either x or y direction) then the result with the lower quality will be eliminated from the result list.

◆ Inspect() [1/2]

bool Inspect ( const Image img,
SearchResult res,
int &  searchDepth 
)
inline

Carries out the operation that GridSearch executes for a grid point, starting at the perspective and position defined by the initial value of the parameter SearchResult.

Parameters
[in]imgImage to work on.
[in,out]resSearch Result to start with (upon exit: final result).
[in,out]searchDepthMaximum number of steps to calculate (upon exit: number of steps actually calculated).
Returns
True if the SearchPredictor found a result when starting at the position defined through the res parameter, false otherwise.
Exceptions
Anyexception derived from std::exception including CvbException.

When the function returns successfully, SearchResult will contain the final perspective and result quality. For additional information please see the tutorial on search functions of Polimago.

◆ Inspect() [2/2]

bool Inspect ( const Image img,
SearchResult res,
int &  searchDepth,
std::vector< SearchResult > &  trace 
)
inline

Carries out the operation that GridSearch executes for a grid point, starting at the perspective and position defined by the initial value of the parameter SearchResult.

Parameters
[in]imgImage to work on.
[in,out]resSearch Result to start with (upon exit: final result).
[in,out]searchDepthMaximum number of steps to calculate (upon exit: number of steps actually calculated).
[out]traceSearch results that lead from the initial value of the res parameter to the final value.
Returns
True if the SearchPredictor found a result when starting at the position defined through the res parameter, false otherwise.
Exceptions
Anyexception derived from std::exception including CvbException.

When the function returns successfully, SearchResult will contain the final perspective and result quality. For additional information please see the tutorial on search functions of Polimago.

◆ Invariances()

InvarianceType Invariances ( ) const
inlinenoexcept

Get the invariances that have been trained on this classifier.

Returns
Invariance type.
Exceptions
Doesnot throw any exception.

◆ Load()

static std::unique_ptr< SearchPredictor > Load ( const String fileName)
inlinestatic

Load a saved predictor from a file.

Parameters
[in]fileNameName of the file to be loaded.
Returns
Pointer to the loaded predictor.
Exceptions
Anyexception derived from std::exception including CvbException.
Examples
Polimago/QmlCookieClassification.

◆ MaxNumResults()

int MaxNumResults ( ) const
inlinenoexcept

Get the maximum number of results that can be extracted in a GridSearch operation.

Returns
Maximum number of results.
Exceptions
Doesnot throw any exception.

◆ NumClassificationSteps()

int NumClassificationSteps ( ) const
inlinenoexcept

Get the number of classification steps defined during training.

Returns
Number of classification steps.
Exceptions
Doesnot throw any exception.

◆ RotationRange()

ValueRange< Angle > RotationRange ( ) const
inlinenoexcept

Get the range of angles that was covered during classifier training.

Returns
Rotation range.
Exceptions
Doesnot throw any exception.

◆ SampleSize()

int SampleSize ( ) const
inlinenoexcept

Get the sample size that has been used in each training set.

Returns
Sample size.
Exceptions
Doesnot throw any exception.

◆ ScaleRange()

ValueRange< double > ScaleRange ( ) const
inlinenoexcept

Get the range of scale factors that was covered during classifier training.

Returns
Scale range.
Exceptions
Doesnot throw any exception.

◆ SearchResultToImage()

std::unique_ptr< Image > SearchResultToImage ( const Image sourceImage,
SearchResult  res 
)
inline

Create a visual representation of a search result.

Parameters
[in]sourceImageImage to create the representation from. This should be the image on which the result was found with this classifier.
[in]resSearch result (should match the image and this classifier).
Returns
Visual representation of the search result.
Exceptions
Anyexception derived from std::exception including CvbException.

◆ SetMaxNumResults()

void SetMaxNumResults ( int  maxNumResults)
inline

Set the maximum number of results that can be extracted in a GridSearch operation. Increasing this value will increase the amount of memory allocated by this SearchPredictor object.

Parameters
[in]maxNumResultsThe maximum number of results.
Exceptions
Anyexception derived from std::exception including CvbException.