3#include "../_cexports/c_sample_database.h"
5#include "../global.hpp"
7#include "../string.hpp"
8#include "../point_2d.hpp"
21namespace SampleDatabase
27size_t GetFloatRegressionDimension (CExports::TSIL hSil)
29 auto labelType = CVB_CALL_CAPI (SilGetLabelType(hSil));
31 CVB_CALL_CAPI_CHECKED (SilGetFloatVectorLabelDim(labelType, dim));
35inline void ValidateLabel (CExports::TSIL ,
const String &label)
45 if (label.size () != GetFloatRegressionDimension (hSil))
52inline void Relabel (CExports::TSIL hSil,
int index,
const String &label)
54 ValidateLabel (hSil, label);
56 CVB_CALL_CAPI_CHECKED(SilChangeStringLabelTyped(hSil, index, label.c_str()));
62 ValidateLabel (hSil, label);
65 CVB_CALL_CAPI_CHECKED(SilChangeVectorLabel(hSil, index,
const_cast<float*
>(label.data()), label.size()));
69template<
typename TLabelOut,
typename TLabelIn>
70using LabelTransform =
std::function<TLabelOut (
const TLabelIn &labelIn)>;
76template <
class TLabelInformation>
81 : shandleSil_(sguardSil)
91 using LabelType =
typename TLabelInformation::LabelType;
101 return CVB_CALL_CAPI(SilGetNumLabelEntries(shandleSil_.Handle()));
113 return GetInfo (index);
124 auto count =
Count ();
126 for (
decltype(count) i = 0; i < count; ++i)
142 CVB_CALL_CAPI_CHECKED(SilDeleteLabel(shandleSil_.Handle(), index));
153 auto index = LabelToIndex(label);
187 if (fromIndex == toIndex)
191 Private::Relabel (shandleSil_.Handle (), fromIndex,
ReadInfo (toIndex).Label ());
205 auto fromIndex = LabelToIndex (fromLabel);
206 auto toIndex = LabelToIndex (toLabel);
207 if (fromIndex < 0 || toIndex < 0)
217 virtual TLabelInformation GetInfo (
int index)
const = 0;
219 int LabelToIndex (
const LabelType &label)
const
221 auto count =
Count ();
222 for (
int i = 0; i < count; ++i)
232 SharedReleaseObjectGuard shandleSil_;
238template <
class TData>
243 : shandleSil_(sguardSil)
260 auto label = CVB_CALL_CAPI(SilGetLabel (shandleSil_.Handle(), GetLabelIndex()));
261 return CVB_CALL_CAPI(SilGetNumDataReferences(label));
273 auto data = CVB_CALL_CAPI(SilGetDataByLabel (shandleSil_.Handle(), GetLabelIndex(), index));
274 return GetData (data);
287 CVB_CALL_CAPI_CHECKED(SilDeleteDataByLabel(shandleSil_.Handle(), GetLabelIndex(), index));
294 return Internal::DoBoolCallObjectOut<Image>([&](
void* & resimg)
296 CVB_CALL_CAPI_CHECKED(SilGetImageData (dataHandle, resimg));
297 return CVB_CALL_CAPI(ShareObject (resimg));
301 int GetLabelIndex ()
const
306 virtual TData GetData (CExports::TSILDATA dataHandle)
const = 0;
309 SharedReleaseObjectGuard shandleSil_;
363 : shandleSil_(std::move(guardSil)),
374 static ReleaseObjectGuard LoadInternal (
const String & fileName, CExports::TSilLabelType expectedLabelType)
376 CExports::TSIL sil =
nullptr;
378 CVB_CALL_CAPI_CHECKED (SilLoadTyped (fileName.c_str(), sil));
379 ReleaseObjectGuard silGuard (sil);
381 auto dataType = CVB_CALL_CAPI (SilGetDataTypeEnum(silGuard.Handle()));
382 auto labelType = CVB_CALL_CAPI (SilGetLabelTypeEnum(silGuard.Handle()));
383 if (dataType != CExports::SDT_ImageData)
387 if (labelType != expectedLabelType)
405 return shandleSil_.Handle();
425 size_t bufferSize = 0;
426 CVB_CALL_CAPI_CHECKED (SilGetCommentTyped(
Handle(),
static_cast<Char*
>(
nullptr), bufferSize));
428 CVB_CALL_CAPI_CHECKED (SilGetCommentTyped(
Handle(), comment.data(), bufferSize));
429 return String (comment.begin(), comment.end());
439 CVB_CALL_CAPI_CHECKED (SilSetCommentTyped (
Handle(), comment.c_str()));
449 CExports::CV_SYSTEMTIME st;
450 CVB_CALL_CAPI_CHECKED (SilGetCreationDate(
Handle(), st));
452 tm.tm_sec = st.wSecond;
453 tm.tm_min = st.wMinute;
454 tm.tm_hour = st.wHour;
455 tm.tm_mday = st.wDay;
456 tm.tm_mon = st.wMonth - 1;
457 tm.tm_year = st.wYear - 1900;
470 CExports::CV_SYSTEMTIME st;
471 CVB_CALL_CAPI_CHECKED (SilGetModificationDate(
Handle(), st));
473 tm.tm_sec = st.wSecond;
474 tm.tm_min = st.wMinute;
475 tm.tm_hour = st.wHour;
476 tm.tm_mday = st.wDay;
477 tm.tm_mon = st.wMonth - 1;
478 tm.tm_year = st.wYear - 1900;
491 size_t numClasses, dummy1, dummy2;
493 CVB_CALL_CAPI_CHECKED(SilGetStatistics(
Handle(), numClasses, dummy1, dummy2, dummy3));
494 return static_cast<int>(numClasses);
504 return static_cast<int>(CVB_CALL_CAPI(SilGetNumDataEntries(
Handle())));
514 size_t minCount, dummy1, dummy2;
516 CVB_CALL_CAPI_CHECKED(SilGetStatistics(
Handle(), dummy1, minCount, dummy2, dummy3));
517 return static_cast<int>(minCount);
527 size_t maxCount, dummy1, dummy2;
529 CVB_CALL_CAPI_CHECKED(SilGetStatistics(
Handle(), dummy1, dummy2, maxCount, dummy3));
530 return static_cast<int>(maxCount);
540 size_t dummy1, dummy2, dummy3;
542 CVB_CALL_CAPI_CHECKED(SilGetStatistics(
Handle(), dummy1, dummy2, dummy3, avgCount));
555 CVB_CALL_CAPI_CHECKED (SilStoreTyped (
Handle(), fileName.c_str()));
556 fileName_ = fileName;
561 template <
class TOut>
564 CExports::TSIL sil =
nullptr;
566 CVB_CALL_CAPI_CHECKED (SilTransformDataList (
Handle (), NativeDataTransformCallback, &cbk, sil));
567 ReleaseObjectGuard silGuard (sil);
569 return TOut::FromHandle (std::move (silGuard));
572 template <
class TOut,
class TLabelOut,
class TLabelIn>
575 CExports::TSIL sil =
nullptr;
577 CVB_CALL_CAPI_CHECKED (SilTransformLabelList (
Handle (), NativeLabelTransformCallback<TLabelOut, TLabelIn>, &cbk, sil));
578 ReleaseObjectGuard silGuard (sil);
580 return TOut::FromHandle (std::move (silGuard));
584 static CExports::cvbbool_t __stdcall NativeDataTransformCallback (
void* pPrivate, CExports::TSILDATA DataIn, CExports::TSILDATA& DataOut)
590 auto imgIn = Internal::DoBoolCallObjectOut<Image>([&](
void* & resimg)
592 CVB_CALL_CAPI_CHECKED(SilGetImageData (DataIn, resimg));
593 return CVB_CALL_CAPI(ShareObject (resimg));
596 auto imgOut = (*cbk) (*imgIn);
597 DataOut = CVB_CALL_CAPI(SilCreateImageData(imgOut->Handle(), 0, 0, imgOut->Size().Width(), imgOut->Size().Height()));
606 template <
class TLabelOut,
class TLabelIn>
607 static CExports::cvbbool_t __stdcall NativeLabelTransformCallback (
void* pPrivate, CExports::TSILLABEL LabelIn, CExports::TSILLABEL& LabelOut)
611 Private::LabelTransform<TLabelOut, TLabelIn> *cbk =
reinterpret_cast<Private::LabelTransform<TLabelOut, TLabelIn>*
> (pPrivate);
614 NativeLabelToObject (LabelIn, objectIn);
616 auto objectOut = (*cbk) (objectIn);
617 LabelOut = CreateNativeLabel (objectOut);
626 static void NativeLabelToObject (CExports::TSILLABEL label, String &
object)
628 size_t bufferSize = 0;
629 CVB_CALL_CAPI_CHECKED (SilGetStringLabelTyped(label,
static_cast<Char*
>(
nullptr), bufferSize));
631 CVB_CALL_CAPI_CHECKED (SilGetStringLabelTyped(label, stringLabel.data(), bufferSize));
632 object.assign (stringLabel.begin (), stringLabel.end ());
635 static CExports::TSILLABEL CreateNativeLabel (
const String &
object)
637 return CVB_CALL_CAPI(SilCreateStringLabelTyped(
object.c_str()));
640 static void NativeLabelToObject (CExports::TSILLABEL label,
std::vector<float> &
object)
643 CVB_CALL_CAPI_CHECKED (SilGetFloatVectorLabel(label,
static_cast<float*
>(
nullptr), dim));
645 CVB_CALL_CAPI_CHECKED (SilGetFloatVectorLabel(label,
object.data(), dim));
650 return CVB_CALL_CAPI(SilCreateVectorLabel(
object.data(),
object.size()));
654 SharedReleaseObjectGuard shandleSil_;
The Common Vision Blox image.
Definition: decl_image.hpp:45
Information collection for class labels.
Definition: sample_list.hpp:78
void MergeClasses(const LabelType &fromLabel, const LabelType &toLabel)
Merge two classes into one class.
Definition: sample_list.hpp:203
typename TLabelInformation::LabelType LabelType
Type of the labels.
Definition: sample_list.hpp:91
std::vector< TLabelInformation > ReadInfos() const
Retrieves all the items stored in the collection.
Definition: sample_list.hpp:122
void Remove(const LabelType &label)
Remove a class and all the data objects associated with it based on its name.
Definition: sample_list.hpp:151
int Count() const
Retrieves the number of elements in the collection.
Definition: sample_list.hpp:99
TLabelInformation ReadInfo(int index) const
Retrieves the indexed item.
Definition: sample_list.hpp:111
void Clear()
Remove all labels (and their associated data) from the sample list.
Definition: sample_list.hpp:168
void MergeClasses(int fromIndex, int toIndex)
Merge two classes into one class.
Definition: sample_list.hpp:185
void RemoveAt(int index)
Remove a class by index.
Definition: sample_list.hpp:140
Collection of data samples.
Definition: sample_list.hpp:240
TData RemoveAt(int index)
Remove a sample.
Definition: sample_list.hpp:284
int Count() const
Get the number of samples for this collection.
Definition: sample_list.hpp:258
TData ReadData(int index) const
Access one of the sample images.
Definition: sample_list.hpp:271
Base class for sample lists.
Definition: sample_list.hpp:360
int NumClasses() const
Number of distinguishable classes in the sample list.
Definition: sample_list.hpp:489
std::chrono::system_clock::time_point CreationDate() const
Date on which the sample list was created.
Definition: sample_list.hpp:447
String Comment() const
Get the comment text.
Definition: sample_list.hpp:423
void Save(const String &fileName) const
Save the sample list to a file.
Definition: sample_list.hpp:553
double AverageSampleCount() const
Average number samples in per class of the sample list.
Definition: sample_list.hpp:538
void SetComment(String comment)
Set the comment text.
Definition: sample_list.hpp:437
std::chrono::system_clock::time_point ModificationDate() const
Date on which the sample list was modified.
Definition: sample_list.hpp:468
int MaxSampleCount() const
Number samples in the largest class of the sample list.
Definition: sample_list.hpp:525
int NumSamples() const
Total number of samples in the sample list.
Definition: sample_list.hpp:502
String FileName() const
Name of the file from which this image list was loaded (empty string if this image list was neither l...
Definition: sample_list.hpp:413
int MinSampleCount() const
Number samples in the smallest class of the sample list.
Definition: sample_list.hpp:512
void * Handle() const noexcept
Classic API SIL handle.
Definition: sample_list.hpp:403
@ Private
Private name space.
std::function< std::vector< float >(const std::vector< float > &labelIn)> LabelTransformVectorToVector
Callback for label transformation.
Definition: sample_list.hpp:334
std::function< String(const String &labelIn)> LabelTransformStringToString
Callback for label transformation.
Definition: sample_list.hpp:318
std::function< String(const std::vector< float > &labelIn)> LabelTransformVectorToString
Callback for label transformation.
Definition: sample_list.hpp:342
std::function< std::vector< float >(const String &labelIn)> LabelTransformStringToVector
Callback for label transformation.
Definition: sample_list.hpp:326
std::function< std::unique_ptr< Image >(const Image &imgIn)> DataTransformImageToImage
Image data transformation callback.
Definition: sample_list.hpp:350
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
char Char
Character type for wide characters or unicode characters.
Definition: string.hpp:59
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:45