3#include "../../_cexports/c_sample_database.h"
5#include "../../global.hpp"
6#include "../../image.hpp"
7#include "../../string.hpp"
8#include "../sample_image_list.hpp"
9#include "../sample_list_image_data_type.hpp"
26 class ImageClassificationLabelInfo
29 ImageClassificationLabelInfo(
const SharedReleaseObjectGuard &sguardSil,
const String &label)
30 : shandleSil_(sguardSil)
31 , labelInfo_(sguardSil, label)
35 ImageClassificationLabelInfo(
const ImageClassificationLabelInfo &other) =
delete;
36 ImageClassificationLabelInfo &operator=(
const ImageClassificationLabelInfo &other) =
delete;
37 ImageClassificationLabelInfo(ImageClassificationLabelInfo &&other) =
delete;
38 ImageClassificationLabelInfo &operator=(ImageClassificationLabelInfo &&other) =
delete;
39 virtual ~ImageClassificationLabelInfo() =
default;
52 return labelInfo_.Samples();
78 return labelInfo_.Label();
88 CExports::cvbbool_t retval =
false;
89 auto label = CVB_CALL_CAPI(SilGetLabel(shandleSil_.Handle(),
Index()));
90 CVB_CALL_CAPI_CHECKED(SilGetExcludedFlag(label, retval));
101 auto label = CVB_CALL_CAPI(SilGetLabel(shandleSil_.Handle(),
Index()));
102 CVB_CALL_CAPI_CHECKED(SilSetExcludedFlag(label, isExcluded));
116 Private::AddSample(shandleSil_.Handle(),
Label(), srcImage, extractionLocation, mode);
128 Private::Relabel(shandleSil_.Handle(),
Index(), label);
132 SharedReleaseObjectGuard shandleSil_;
133 Private::ImageLabelInfo<String> labelInfo_;
26 class ImageClassificationLabelInfo {
…};
143 class ImageClassificationInfoCollection :
public LabelInfoCollection<ImageClassificationLabelInfo>
146 explicit ImageClassificationInfoCollection(
const SharedReleaseObjectGuard &sguardSil)
147 : LabelInfoCollection<ImageClassificationLabelInfo>(sguardSil)
166 Private::AddSample(shandleSil_.Handle(), label, srcImage, extractionLocation, mode);
178 auto count =
Count();
179 for (
int i = 0; i < count; ++i)
192 auto label = CVB_CALL_CAPI(SilGetLabel(shandleSil_.Handle(), index));
193 size_t bufferSize = 0;
194 CVB_CALL_CAPI_CHECKED(SilGetStringLabelTyped(label,
static_cast<Char *
>(
nullptr), bufferSize));
196 CVB_CALL_CAPI_CHECKED(SilGetStringLabelTyped(label, stringLabel.data(), bufferSize));
197 return std::make_unique<ImageClassificationLabelInfo>(shandleSil_,
198 String(stringLabel.begin(), stringLabel.end()));
143 class ImageClassificationInfoCollection :
public LabelInfoCollection<ImageClassificationLabelInfo> {
…};
212 class SampleClassificationImageList :
public SampleImageList
215 explicit SampleClassificationImageList(ReleaseObjectGuard &&guardSil,
const String &fileName =
String())
216 : SampleImageList(
std::move(guardSil), fileName)
228 : SampleClassificationImageList(CreateInternal(imageDataType))
238 : SampleClassificationImageList(ReleaseObjectGuard(LoadInternal(fileName, CExports::SLT_String)), fileName)
246 ReleaseObjectGuard lblType(CVB_CALL_CAPI(SilCreateLabelTypeString()));
247 ReleaseObjectGuard sil(CVB_CALL_CAPI(SilCreate(lblType.Handle(), imageDataType.
Handle())));
269 new SampleClassificationImageList(
std::move(guard), fileName));
280 CExports::TSIL sil =
nullptr;
282 CVB_CALL_CAPI_CHECKED(SilImportFromMantoTyped(fileName.c_str(), sil));
283 ReleaseObjectGuard silGuard(sil);
306 return TransformData<SampleClassificationImageList>(transformCallback);
317 return TransformLabels<SampleClassificationImageList>(transformCallback);
336 auto dataHandle = CVB_CALL_CAPI(SilGetData(
Handle(), sampleIndex));
337 auto labelRef = CVB_CALL_CAPI(SilGetLabelReference(dataHandle, 0));
338 auto labelIndex = CVB_CALL_CAPI(SilGetLabelIndex(
Handle(), labelRef));
339 return Classes()->ReadInfo(labelIndex);
354 auto dataHandle = CVB_CALL_CAPI(SilGetData(
Handle(), sampleIndex));
355 auto labelRef = CVB_CALL_CAPI(SilGetLabelReference(dataHandle, 0));
356 auto count = CVB_CALL_CAPI(SilGetNumDataReferences(labelRef));
357 clsIdx =
static_cast<int>(CVB_CALL_CAPI(SilGetLabelIndex(
Handle(), labelRef)));
358 for (
decltype(count) i = 0; i < count; ++i)
360 auto testDataHandle = CVB_CALL_CAPI(SilGetDataByLabel(
Handle(), clsIdx, i));
361 if (testDataHandle == dataHandle)
363 splIdx =
static_cast<int>(i);
212 class SampleClassificationImageList :
public SampleImageList {
…};
The Common Vision Blox image.
Definition decl_image.hpp:50
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
bool HasLabel(const String &label)
Check if a given label is already present in the classes collection.
Definition decl_classification_sil.hpp:176
void Add(const String &label, const Image &srcImage, Point2D< int > extractionLocation, SampleExtractionMode mode=SampleExtractionMode::TopLeftCorner)
Add a sample to a new class. If the class indicated by the label already exists the sample will be ad...
Definition decl_classification_sil.hpp:163
void SetIsExcluded(bool isExcluded)
Set the exclusion state of this class.
Definition decl_classification_sil.hpp:99
ImageCollectionPtr Samples()
Get samples under this label.
Definition decl_classification_sil.hpp:50
void Add(const Image &srcImage, Point2D< int > extractionLocation, SampleExtractionMode mode=SampleExtractionMode::TopLeftCorner)
Add a new sample to an existing class.
Definition decl_classification_sil.hpp:113
String Label() const
Get label under which this class is stored.
Definition decl_classification_sil.hpp:76
void Relabel(const String &label)
Modify the label of a sample set, but not to one that already exists in the sample list.
Definition decl_classification_sil.hpp:126
String LabelType
Type of the labels.
Definition decl_classification_sil.hpp:43
int Index() const
Get the index of this label.
Definition decl_classification_sil.hpp:63
bool IsExcluded() const
Get the exclusion state of this class.
Definition decl_classification_sil.hpp:86
std::unique_ptr< ImageClassificationLabelInfo > ReadInfo(int index) const
Definition sample_list.hpp:115
int Count() const
Definition sample_list.hpp:103
SampleClassificationImageList(const SampleListImageDataType &imageDataType)
Create a sample image list suitable for classification tasks.
Definition decl_classification_sil.hpp:227
SampleClassificationImageList(const String &fileName)
Load a sample classification image from a file.
Definition decl_classification_sil.hpp:237
std::unique_ptr< ImageClassificationLabelInfo > GetClassFromSample(int sampleIndex)
Retrieve the label information that goes with a given sample.
Definition decl_classification_sil.hpp:334
static std::unique_ptr< SampleClassificationImageList > ImportMantoSil(const String &fileName)
Load a Manto2 sample list from disc.
Definition decl_classification_sil.hpp:278
static std::unique_ptr< SampleClassificationImageList > FromHandle(ReleaseObjectGuard &&guard, const String &fileName=String())
Creates classification image list from a classic API handle.
Definition decl_classification_sil.hpp:261
ImageClassificationInfoCollectionPtr Classes()
Get the class collection.
Definition decl_classification_sil.hpp:293
std::unique_ptr< SampleClassificationImageList > Transform(LabelTransformStringToString transformCallback) const
Transform this sample image list into a new sample image list by transforming each label inside it.
Definition decl_classification_sil.hpp:315
void GetIndicesForSampleIndex(int sampleIndex, int &clsIdx, int &splIdx) const
For a given sample index (running from 0 to NumSamples()-1) this method determines the indices of the...
Definition decl_classification_sil.hpp:350
std::unique_ptr< SampleClassificationImageList > Transform(DataTransformImageToImage transformCallback) const
Transform this sample image list into a new sample image list by transforming each sample inside it.
Definition decl_classification_sil.hpp:304
void * Handle() const noexcept
Classic API SIL handle.
Definition sample_list.hpp:411
Descriptor for image data to be digested by an image list.
Definition sample_list_image_data_type.hpp:25
void * Handle() const noexcept
Classic API SIL handle.
Definition sample_list_image_data_type.hpp:105
Classifier type that operates on images.
Definition decl_regression_sil.hpp:190
Namespace for the SampleDatabase package.
Definition decl_classification_sil.hpp:20
std::shared_ptr< ImageClassificationInfoCollection > ImageClassificationInfoCollectionPtr
Convenience shared pointer for ImageClassificationInfoCollection.
Definition decl_classification_sil.hpp:203
std::function< std::vector< float >(const String &labelIn)> LabelTransformStringToVector
Callback for label transformation.
Definition sample_list.hpp:331
std::shared_ptr< ImageClassificationLabelInfo > ImageClassificationLabelInfoPtr
Convenience shared pointer for ImageClassificationLabelInfo.
Definition decl_classification_sil.hpp:137
std::shared_ptr< ImageCollection > ImageCollectionPtr
Convenience shared pointer for ImageCollection.
Definition sample_image_list.hpp:108
std::function< std::unique_ptr< Image >(const Image &imgIn)> DataTransformImageToImage
Image data transformation callback.
Definition sample_list.hpp:355
SampleExtractionMode
Possible approaches to the sample extraction in the "Add" methods of image list classes.
Definition sample_image_list.hpp:25
@ TopLeftCorner
Position parameter is assumed to refer to the top left corner of the feature window.
Definition sample_image_list.hpp:27
std::shared_ptr< SampleClassificationImageList > SampleClassificationImageListPtr
Convenience shared pointer for SampleClassificationImageList.
Definition decl_classification_sil.hpp:374
std::function< String(const String &labelIn)> LabelTransformStringToString
Callback for label transformation.
Definition sample_list.hpp:323
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