3#include "../_cexports/c_minos.h"
5#include "../global.hpp"
7#include "../string.hpp"
8#include "../point_2d.hpp"
9#include "../matrix_2d.hpp"
10#include "../image.hpp"
12#include "learn_parameters.hpp"
13#include "search_result.hpp"
34 inline HandleGuard<Minos::Classifier>::HandleGuard(
void *handle) noexcept
35 : HandleGuard<Minos::Classifier>(handle, [](
void *h) { CVB_CALL_CAPI(
ReleaseObject(h)); })
103 , advanceVector_(advanceVector)
134 return advanceVector_;
144 advanceVector_ = advanceVector;
162 return (lhs.Name() != rhs.Name()) || (lhs.AdvanceVector() != rhs.AdvanceVector());
175 return (!(lhs != rhs));
181 class ClassifierModelInfoCollection
184 explicit ClassifierModelInfoCollection(
const SharedHandleGuard<Classifier> &sguard)
189 ClassifierModelInfoCollection(
const ClassifierModelInfoCollection &other)
noexcept =
default;
190 ClassifierModelInfoCollection &operator=(
const ClassifierModelInfoCollection &other)
noexcept =
default;
191 ClassifierModelInfoCollection(ClassifierModelInfoCollection &&other)
noexcept =
default;
192 ClassifierModelInfoCollection &operator=(ClassifierModelInfoCollection &&other)
noexcept =
default;
193 ~ClassifierModelInfoCollection() =
default;
203 return static_cast<int>(CVB_CALL_CAPI(NumCLFModels(shandle_.Handle())));
215 Char *pstr =
nullptr;
216 CExports::cvbdim_t advX = 0, advY = 0;
217 CVB_CALL_CAPI_CHECKED(GetCLFModelDataTyped(shandle_.Handle(), index, pstr, advX, advY));
220 Point2D<int>(
static_cast<int>(advX),
static_cast<int>(advY)));
236 CVB_CALL_CAPI_CHECKED(SetCLFModelDataTyped(shandle_.Handle(), index, model.
Name().c_str(),
248 auto count =
Count();
250 for (
decltype(count) i = 0; i < count; ++i)
259 SharedHandleGuard<Classifier> shandle_;
181 class ClassifierModelInfoCollection {
…};
269 explicit Classifier(HandleGuard<Classifier> &&guard,
const String &srcFileName =
String())
271 , fileName_(srcFileName)
275 auto strDate = CVB_CALL_CAPI(CLFCreationDate(shandle_.Handle()));
298 CExports::cvbdim_t left = 0, top = 0, right = 0, bottom = 0;
299 CVB_CALL_CAPI_CHECKED(GetCLFExtent(shandle_.Handle(), left, top, right, bottom));
301 Rect<int>(
static_cast<int>(left),
static_cast<int>(top),
static_cast<int>(right),
static_cast<int>(bottom));
305 static CExports::cvbval_t MaxSearch()
noexcept
317 : Classifier(std::move(*
Load(fileName)))
336 CExports::CLF clf =
nullptr;
337 CVB_CALL_CAPI_CHECKED(LoadCLFFileTyped(fileName.c_str(), clf));
350 return Internal::DoBoolCallObjectOut<Classifier>([&](
void *&resclas) {
352 return CVB_CALL_CAPI(MemoryToCLF(
const_cast<void *
>(buffer),
static_cast<long>(size),
363 template <
class RANGE>
366 auto bufferRange = MakeRangeAdapter<std::uint8_t>(buffer);
367 return FromBuffer(bufferRange.Data(), bufferRange.Size());
379 return shandle_.Handle();
407 CVB_CALL_CAPI_CHECKED(WriteCLFFileTyped(shandle_.Handle(), fileName.c_str()));
408 fileName_ = fileName;
419 auto sizeNeeded = CVB_CALL_CAPI(GetCLFSize(
Handle()));
421 CVB_CALL_CAPI_CHECKED(CLFToMemory(shandle_.Handle(), buffer.data(), sizeNeeded));
466 return creationDate_;
476 return CVB_CALL_CAPI(IsOldCLF(shandle_.Handle()) ?
true :
false);
486 CExports::cvbval_t retval = 0;
487 CVB_CALL_CAPI_CHECKED(GetCLFTrigger(shandle_.Handle(), retval));
488 return static_cast<int>(retval);
498 CVB_CALL_CAPI_CHECKED(SetCLFTrigger(shandle_.Handle(),
static_cast<CExports::cvbval_t
>(trigger)));
509 CVB_CALL_CAPI_CHECKED(GetCLFThreshold(shandle_.Handle(), retval));
520 CVB_CALL_CAPI_CHECKED(SetCLFThreshold(shandle_.Handle(), threshold));
530 CExports::QualityMeasureMethod retval = CExports::Quality_Unnormalized;
531 CVB_CALL_CAPI_CHECKED(GetCLFQualityType(shandle_.Handle(), retval));
542 CVB_CALL_CAPI_CHECKED(
543 SetCLFQualityType(shandle_.Handle(),
static_cast<CExports::QualityMeasureMethod
>(quality)));
553 const Char *name =
nullptr;
554 CVB_CALL_CAPI(CLFMTSNameTyped(shandle_.Handle(), name));
565 CExports::TLearnControlStructure params{0};
566 CVB_CALL_CAPI_CHECKED(GetCLFLCS(shandle_.Handle(), params));
568 params.Param2 / 1000.0);
578 const Char *comment =
nullptr;
579 CVB_CALL_CAPI(CLFCommentTyped(shandle_.Handle(), comment));
580 return (comment !=
nullptr) ?
String(comment) :
String();
590 CVB_CALL_CAPI_CHECKED(SetCLFCommentTyped(shandle_.Handle(), comment.c_str()));
602 return Internal::DoBoolCallObjectOut<Classifier>([&](
void *&resclas) {
605 return CVB_CALL_CAPI(
606 CLFTransform(
Handle(),
reinterpret_cast<const CExports::TMatrix &
>(transformation), resclas));
620 return Internal::DoBoolCallObjectOut<Classifier>([&](
void *&resclas) {
621 return CVB_CALL_CAPI(CLFSetGlobalAdvance(
Handle(),
static_cast<CExports::cvbdim_t
>(advance.X()),
622 static_cast<CExports::cvbdim_t
>(advance.Y()), resclas));
648 double density = 1.0)
650 double quality = 0.0, xPos = 0.0, yPos = 0.0, dX = 0.0, dY = 0.0;
651 Char *pstr =
nullptr;
652 CExports::cvbval_t charCount = 0;
660 CVB_CALL_CAPI_CHECKED(ReadTokenFirstTyped(
662 reinterpret_cast<const CExports::TArea &
>(startAOI),
reinterpret_cast<const CExports::TArea &
>(ocrAOI),
663 MaxSearch(), quality, xPos, yPos, dX, dY, pstr, charCount, token.data()));
666 CVB_CALL_CAPI_CHECKED(ReadTokenTyped(
668 reinterpret_cast<const CExports::TArea &
>(startAOI),
reinterpret_cast<const CExports::TArea &
>(ocrAOI),
669 MaxSearch(), quality, xPos, yPos, dX, dY, pstr, charCount, token.data()));
674 return String(token.data());
697 CExports::RESULTS hSearchResults =
nullptr;
698 CVB_CALL_CAPI_CHECKED(
700 reinterpret_cast<const CExports::TArea &
>(startAOI),
701 reinterpret_cast<const CExports::TArea &
>(ocrAOI), MaxSearch(), hSearchResults));
702 ReleaseObjectGuard hSearchResHolder(hSearchResults);
703 return Private::SearchResultsToArray(hSearchResults);
718 double quality = 0.0, xPos = 0.0, yPos = 0.0, dX = 0.0, dY = 0.0;
719 Char *pstr =
nullptr;
726 CVB_CALL_CAPI_CHECKED(
728 reinterpret_cast<const CExports::TArea &
>(aoi), quality, xPos, yPos, dX, dY, pstr));
731 CVB_CALL_CAPI_CHECKED(
733 reinterpret_cast<const CExports::TArea &
>(aoi), quality, xPos, yPos, dX, dY, pstr));
736 CVB_CALL_CAPI_CHECKED(SubpixelOptimumTyped(
738 reinterpret_cast<const CExports::TArea &
>(aoi), quality, xPos, yPos, dX, dY, pstr));
773 CExports::RESULTS hSearchResults =
nullptr;
774 CVB_CALL_CAPI_CHECKED(
776 reinterpret_cast<const CExports::TArea &
>(aoi), locality, MaxSearch(), hSearchResults));
777 ReleaseObjectGuard hSearchResHolder(hSearchResults);
778 return Private::SearchResultsToArray(hSearchResults);
796 SharedHandleGuard<Classifier> shandle_;
799 std::chrono::system_clock::time_point creationDate_;
265 class Classifier {
…};
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:438
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Image plane information container.
Definition decl_image_plane.hpp:29
int Plane() const noexcept
Plane index in the image, to which this plane refers to.
Definition decl_image_plane.hpp:147
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition detail_image_plane.hpp:87
Double precision 2x2 matrix class.
Definition matrix_2d.hpp:16
Minos classifier object.
Definition classifier.hpp:266
std::vector< SearchResult > Read(const ImagePlane &plane, Area2D startAOI, Area2D ocrAOI, double density=1.0)
Reads a list of characters.
Definition classifier.hpp:695
int ContrastTrigger() const
Get the trigger value for the contrast of features to be taken into account.
Definition classifier.hpp:484
static TypedRange< std::unique_ptr< Classifier >, std::uint8_t, RANGE >::type FromBuffer(const RANGE &buffer)
Recreate a serialized Minos classifier from a byte array.
Definition classifier.hpp:364
class LearnParameters LearnParameters() const
Get the set of parameters that has been used during classifier generation.
Definition classifier.hpp:563
std::unique_ptr< Classifier > Transform(Matrix2D transformation)
Generate a new classifier by transforming this classifier with a 2x2 transformation matrix.
Definition classifier.hpp:600
std::chrono::system_clock::time_point CreationDate() const noexcept
Creation date of the classifier.
Definition classifier.hpp:464
bool IsMinos16BitClassifier() const
Returns true if the classifier was generated by Minos16Bit.
Definition classifier.hpp:474
std::vector< SearchResult > SearchAll(const ImagePlane &plane, int locality, double density=1.0)
Search all objects using this Minos classifier.
Definition classifier.hpp:790
SearchResult Search(const ImagePlane &plane, SearchMode mode, double density=1.0)
Search one object using this Minos classifier.
Definition classifier.hpp:755
static std::unique_ptr< Classifier > FromHandle(HandleGuard< Classifier > &&guard)
Creates classifier from a classic API handle.
Definition classifier.hpp:390
void SetQualityMeasure(QualityFeedback quality)
Set the type of quality feedback from the classifier.
Definition classifier.hpp:540
SearchResult Search(const ImagePlane &plane, SearchMode mode, Area2D aoi, double density=1.0)
Search one object using this Minos classifier.
Definition classifier.hpp:716
String Comment() const
Get the comment assigned to the classifier at generation time.
Definition classifier.hpp:576
std::vector< std::uint8_t > ToBuffer() const
Builds a byte buffer with the classifier.
Definition classifier.hpp:417
void Save(const String &fileName) const
Write the classifier to a file.
Definition classifier.hpp:405
Classifier(const String &fileName)
Loads a classifier with the given file name.
Definition classifier.hpp:316
void SetComment(String comment)
Set the comment assigned to the classifier at generation time.
Definition classifier.hpp:588
double Threshold() const
Get the threshold for search operations with normalized quality feedback.
Definition classifier.hpp:506
static std::unique_ptr< Classifier > Load(const String &fileName)
Load a saved classifier from a file.
Definition classifier.hpp:334
String Read(const ImagePlane &plane, ReadMode mode, Area2D startAOI, Area2D ocrAOI, SearchResult &startOrStop, double density=1.0)
Reads a string of characters.
Definition classifier.hpp:647
ClassifierModelInfoCollection Models() const
Collection of the models contained in this classifier.
Definition classifier.hpp:444
void SetThreshold(double threshold)
Set the threshold for search operations with normalized quality feedback.
Definition classifier.hpp:518
std::unique_ptr< Classifier > SetGlobalAdvanceVector(Point2D< int > advance)
Create a new classifier, that is a copy of this classifier, but with a global advance vector applied ...
Definition classifier.hpp:618
std::vector< SearchResult > SearchAll(const ImagePlane &plane, int locality, Area2D aoi, double density=1.0)
Search all objects using this Minos classifier.
Definition classifier.hpp:770
Rect< int > Extent() const noexcept
Extent of the classes in the classifier relative to the anchor point.
Definition classifier.hpp:454
String FileName() const
Name of the file from which this classifier was loaded (empty string, if this image list was neither ...
Definition classifier.hpp:431
void * Handle() const noexcept
Classic API CLF handle.
Definition classifier.hpp:377
String TrainingSetName() const
Get name of the training set from which this classifier was generated.
Definition classifier.hpp:551
static std::unique_ptr< Classifier > FromBuffer(const void *buffer, size_t size)
Recreate a serialized Minos classifier from a byte array.
Definition classifier.hpp:348
QualityFeedback QualityMeasure() const
Get the type of quality feedback from the classifier.
Definition classifier.hpp:528
void SetContrastTrigger(int trigger)
Set the trigger value for the contrast of features to be taken into account.
Definition classifier.hpp:496
Collection of model information.
Definition classifier.hpp:182
ClassifierModelInfo ReadInfo(int index) const
Retrieves the indexed model information block.
Definition classifier.hpp:213
void WriteInfo(int index, ClassifierModelInfo model)
Writes the indexed model information block.
Definition classifier.hpp:230
int Count() const
Retrieves the number of elements in the collection.
Definition classifier.hpp:201
std::vector< ClassifierModelInfo > ReadInfo() const
Retrieves all the items stored in the collection.
Definition classifier.hpp:246
Information about a Minos classifier model.
Definition classifier.hpp:93
String Name() const
Get the name of the model.
Definition classifier.hpp:112
Point2D< int > AdvanceVector() const
Get the advance vector of the model.
Definition classifier.hpp:132
void SetAdvanceVector(Point2D< int > advanceVector)
Set the advance vector of the model.
Definition classifier.hpp:142
ClassifierModelInfo(const String &name, Point2D< int > advanceVector)
Create a new model information object.
Definition classifier.hpp:101
void SetName(const String &name)
Set the name of the model.
Definition classifier.hpp:122
The set of parameters, which controls, how a classifier is being learned from a training set.
Definition learn_parameters.hpp:19
Search result returned by Minos.
Definition search_result.hpp:25
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
Rectangle object.
Definition rect.hpp:24
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for the Minos package.
Definition classifier.hpp:29
bool operator==(const ClassifierModelInfo &lhs, const ClassifierModelInfo &rhs) noexcept
Comparison operator for ClassifierModelInfo objects.
Definition classifier.hpp:173
SearchMode
Different modes for the search calls that return a single result.
Definition classifier.hpp:71
@ FindBest
Search the whole region of interest and return the best result.
Definition classifier.hpp:75
@ FindFirst
Stop after the first result has been found.
Definition classifier.hpp:73
@ FindBestSubPixel
Search the whole region of interest and return the best result with sub pixel accuracy.
Definition classifier.hpp:77
std::shared_ptr< Classifier > ClassifierPtr
Convenience shared pointer for Classifier.
Definition classifier.hpp:804
QualityFeedback
Feedback type for search functions.
Definition classifier.hpp:62
@ Normalized
Normalized quality feedback from correlation over a classifier's features in the range [0....
Definition classifier.hpp:66
@ Unnormalized
Unnormalized quality feedback in the range [0...255].
Definition classifier.hpp:64
ReadMode
Options for the read functions.
Definition classifier.hpp:82
@ ReturnFirstPosition
Return the position of the first character.
Definition classifier.hpp:84
@ ReturnLastPosition
Return the position of the last character.
Definition classifier.hpp:86
bool operator!=(const ClassifierModelInfo &lhs, const ClassifierModelInfo &rhs) noexcept
Comparison operator for ClassifierModelInfo objects.
Definition classifier.hpp:160
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49