3#include "../_cexports/c_sample_database.h"
5#include "../global.hpp"
7#include "../size_2d.hpp"
8#include "../point_2d.hpp"
9#include "../data_type.hpp"
10#include "sample_list.hpp"
35 inline ReleaseObjectGuard CreateNativeImageData(CExports::TSIL hSil,
const Image &srcImage,
39 auto datatype = CVB_CALL_CAPI(SilGetDataType(hSil));
40 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
41 CExports::cvbdatatype_t type = 0;
42 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
45 || srcImage.
Width() <
static_cast<int>(width) || srcImage.
Height() <
static_cast<int>(height))
50 ReleaseObjectGuard data(CVB_CALL_CAPI(
51 SilCreateImageData(srcImage.
Handle(), extractionLocation.
X(), extractionLocation.
Y(), width, height)));
55 inline ReleaseObjectGuard CreateNativeLabel(
const String &label)
57 ReleaseObjectGuard lbl(CVB_CALL_CAPI(SilCreateStringLabelTyped(label.c_str())));
61 inline ReleaseObjectGuard CreateNativeLabel(
const std::vector<float> &label)
63 ReleaseObjectGuard lbl(CVB_CALL_CAPI(SilCreateVectorLabel(label.data(), label.size())));
67 template <
typename TLabel>
68 void AddSample(CExports::TSIL hSil,
const TLabel &label,
const Image &srcImage, Point2D<int> extractionLocation,
71 ValidateLabel(hSil, label);
75 auto datatype = CVB_CALL_CAPI(SilGetDataType(hSil));
76 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
77 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
78 Point2D<int> ftrwinOrigin(
static_cast<int>(originX),
static_cast<int>(originY));
80 extractionLocation -= ftrwinOrigin;
83 ReleaseObjectGuard data(CreateNativeImageData(hSil, srcImage, extractionLocation));
84 ReleaseObjectGuard lbl(CreateNativeLabel(label));
85 CVB_CALL_CAPI_CHECKED(SilAddItem(hSil, data.Handle(), lbl.Handle()));
92 class ImageCollection :
public SampleCollection<std::shared_ptr<Image>>
95 explicit ImageCollection(
const SharedReleaseObjectGuard &sguardSil)
96 : SampleCollection<std::shared_ptr<Image>>(sguardSil)
103 return GetImage(dataHandle);
92 class ImageCollection :
public SampleCollection<std::shared_ptr<Image>> {
…};
113 template <
class TLabel>
117 ImageLabelInfo(
const SharedReleaseObjectGuard &sguardSil,
const TLabel &label)
123 ImageLabelInfo(
const ImageLabelInfo &other) =
delete;
124 ImageLabelInfo &operator=(
const ImageLabelInfo &other) =
delete;
125 ImageLabelInfo(ImageLabelInfo &&other) =
delete;
126 ImageLabelInfo &operator=(ImageLabelInfo &&other) =
delete;
127 virtual ~ImageLabelInfo() =
default;
130 using LabelType = TLabel;
152 class SampleImageList :
public SampleList
155 explicit SampleImageList(ReleaseObjectGuard &&guardSil,
const String &fileName =
String())
156 : SampleList(
std::move(guardSil), fileName)
168 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
170 CExports::cvbdim_t left = 0, top = 0, right = 0, bottom = 0;
171 CVB_CALL_CAPI_CHECKED(SilGetFringes(datatype, left, top, right, bottom));
174 static_cast<int>(bottom));
184 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
186 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
187 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
189 return Size2D<int>(
static_cast<int>(width),
static_cast<int>(height));
199 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
201 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
202 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
204 return Point2D<int>(
static_cast<int>(left),
static_cast<int>(top));
215 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
217 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
218 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
220 return Point2D<int>(
static_cast<int>(originX),
static_cast<int>(originY));
230 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
232 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
233 CExports::cvbdatatype_t type = 0;
234 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
236 return Size2D<int>(
static_cast<int>(width),
static_cast<int>(height));
246 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
248 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
249 CExports::cvbdatatype_t type = 0;
250 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
252 return static_cast<int>(dimension);
262 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
264 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
265 CExports::cvbdatatype_t type = 0;
266 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
285 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
287 CVB_CALL_CAPI_CHECKED(SilSetFeatureWindow(datatype, location.
X(), location.
Y(), size.
Width(), size.
Height(),
288 origin.
X(), origin.
Y()));
304 if (!img.PlaneDataTypesIdentical())
313 if (img.Width() < imageSize.Width())
317 if (img.Height() < imageSize.Height())
333 return Internal::DoBoolCallObjectOut<Image>([&](
void *&resimg) {
334 auto dataHandle = CVB_CALL_CAPI(SilGetData(
Handle(), sampleIndex));
335 CVB_CALL_CAPI_CHECKED(SilGetImageData(dataHandle, resimg));
152 class SampleImageList :
public SampleList {
…};
Data type description for an image plane.
Definition data_type.hpp:23
static DataType FromNativeDescriptor(int dataTypeDescriptor) noexcept
Construct a data type descriptor from one of the native library's descriptor values.
Definition data_type.hpp:31
The Common Vision Blox image.
Definition decl_image.hpp:45
int Width() const noexcept
Width of the image in pixels.
Definition decl_image.hpp:304
int Height() const noexcept
Height of the image in pixels.
Definition decl_image.hpp:294
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition decl_image.hpp:242
std::vector< ImagePlane > Planes() const noexcept
Access all planes for this image.
Definition detail_image.hpp:65
bool PlaneDataTypesIdentical() const noexcept
Check if all planes have the same data type.
Definition decl_image.hpp:252
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
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
Object describing the fringes that are available around images in a sample image list.
Definition fringes.hpp:23
int ImageDimension() const
Dimension (# of planes) of the images that can be added to the image list.
Definition sample_image_list.hpp:244
void SetFeatureWindow(Point2D< int > location, Size2D< int > size, Point2D< int > origin)
Redefine the feature window of the sample image list.
Definition sample_image_list.hpp:283
Size2D< int > FeatureWindowSize() const
Size of the feature window.
Definition sample_image_list.hpp:182
bool IsCompatible(const Image &img) const
Check whether a CVB image is compatible with this image list, i.e. if it is generally possible to add...
Definition sample_image_list.hpp:298
Point2D< int > FeatureWindowOrigin() const
Location of the feature window origin in pixel coordinates measured from the left top corner of the f...
Definition sample_image_list.hpp:213
class Fringes Fringes() const
Get fringes (= size difference between the images and the feature window) of the sample images.
Definition sample_image_list.hpp:166
DataType ImageDataType() const
Data type of the images that can be added to the image list (all planes must have same data type).
Definition sample_image_list.hpp:260
std::shared_ptr< Image > GetSampleImage(int sampleIndex) const
Retrieve an image by its overall sample index (ranging from 0 to NumSamples()-1).
Definition sample_image_list.hpp:331
Size2D< int > ImageSize() const
Size of the images (in pixels) that can be added to the image list.
Definition sample_image_list.hpp:228
Point2D< int > FeatureWindowLocation() const
Location of the feature window (position of left top corner inside the image).
Definition sample_image_list.hpp:197
void * Handle() const noexcept
Classic API SIL handle.
Definition sample_list.hpp:411
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
cvbbool_t ShareObject(OBJ Object)
Namespace for the SampleDatabase package.
Definition decl_classification_sil.hpp:20
std::shared_ptr< SampleImageList > SampleImageListPtr
Convenience shared pointer for SampleImageList.
Definition sample_image_list.hpp:342
std::shared_ptr< ImageCollection > ImageCollectionPtr
Convenience shared pointer for ImageCollection.
Definition sample_image_list.hpp:108
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
@ OriginPosition
Position parameter is assumed to refer to the origin of the feature window.
Definition sample_image_list.hpp:29
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49