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"
22namespace SampleDatabase
38inline ReleaseObjectGuard CreateNativeImageData(CExports::TSIL hSil,
const Image &srcImage,
Point2D<int> extractionLocation)
41 auto datatype = CVB_CALL_CAPI(SilGetDataType(hSil));
42 CExports::cvbdim_t width, height, dimension;
43 CExports::cvbdatatype_t type;
44 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
45 if (srcImage.
PlanesCount() !=
static_cast<int>(dimension)
48 || srcImage.
Width() <
static_cast<int>(width)
49 || srcImage.
Height() <
static_cast<int>(height))
54 ReleaseObjectGuard data (CVB_CALL_CAPI(SilCreateImageData(srcImage.
Handle(), extractionLocation.
X(), extractionLocation.
Y(), width, height)));
58inline ReleaseObjectGuard CreateNativeLabel (
const String &label)
60 ReleaseObjectGuard lbl (CVB_CALL_CAPI(SilCreateStringLabelTyped(label.c_str())));
66 ReleaseObjectGuard lbl (CVB_CALL_CAPI(SilCreateVectorLabel(label.data(), label.size())));
70template<
typename TLabel>
73 ValidateLabel (hSil, label);
77 auto datatype = CVB_CALL_CAPI(SilGetDataType(hSil));
78 CExports::cvbdim_t left, top, width, height, originX, originY;
79 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
80 Point2D<int> ftrwinOrigin (
static_cast<int>(originX),
static_cast<int>(originY));
82 extractionLocation -= ftrwinOrigin;
85 ReleaseObjectGuard data (CreateNativeImageData (hSil, srcImage, extractionLocation));
86 ReleaseObjectGuard lbl (CreateNativeLabel (label));
87 CVB_CALL_CAPI_CHECKED(SilAddItem(hSil, data.Handle(), lbl.Handle()));
110 return GetImage (dataHandle);
117template <
class TLabel>
121 ImageLabelInfo (
const SharedReleaseObjectGuard &sguardSil,
const TLabel &label)
122 : label_(label), samples_(sguardSil)
125 ImageLabelInfo (
const ImageLabelInfo&) =
default;
126 ImageLabelInfo& operator= (
const ImageLabelInfo&) =
default;
128 ~ImageLabelInfo () {};
131 using LabelType = TLabel;
133 ImageCollection Samples()
const
145 ImageCollection samples_;
174 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
176 CExports::cvbdim_t left, top, right, bottom;
177 CVB_CALL_CAPI_CHECKED(SilGetFringes(datatype, left, top, right, bottom));
179 return SampleDatabase::Fringes(
static_cast<int>(left),
static_cast<int>(top),
static_cast<int>(right),
static_cast<int>(bottom));
189 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
191 CExports::cvbdim_t left, top, width, height, originX, originY;
192 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
194 return Size2D<int>(
static_cast<int>(width),
static_cast<int>(height));
204 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
206 CExports::cvbdim_t left, top, width, height, originX, originY;
207 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
209 return Point2D<int>(
static_cast<int>(left),
static_cast<int>(top));
219 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
221 CExports::cvbdim_t left, top, width, height, originX, originY;
222 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
224 return Point2D<int>(
static_cast<int>(originX),
static_cast<int>(originY));
234 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
236 CExports::cvbdim_t width, height, dimension;
237 CExports::cvbdatatype_t type;
238 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
240 return Size2D<int>(
static_cast<int>(width),
static_cast<int>(height));
250 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
252 CExports::cvbdim_t width, height, dimension;
253 CExports::cvbdatatype_t type;
254 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
256 return static_cast<int>(dimension);
266 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
268 CExports::cvbdim_t width, height, dimension;
269 CExports::cvbdatatype_t type;
270 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
287 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
289 CVB_CALL_CAPI_CHECKED(SilSetFeatureWindow(datatype, location.
X(), location.
Y(), size.
Width(), size.
Height(), 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)
335 auto dataHandle = CVB_CALL_CAPI (SilGetData(
Handle(), sampleIndex));
336 CVB_CALL_CAPI_CHECKED(SilGetImageData (dataHandle, resimg));
337 return CVB_CALL_CAPI(ShareObject (resimg));
Data type description for an image plane.
Definition: data_type.hpp:28
static DataType FromNativeDescriptor(int dataTypeDescriptor) noexcept
Construct a data type descriptor from one of the native library's descriptor values.
Definition: data_type.hpp:37
The Common Vision Blox image.
Definition: decl_image.hpp:45
int Width() const noexcept
Width of the image in pixels.
Definition: decl_image.hpp:285
int Height() const noexcept
Height of the image in pixels.
Definition: decl_image.hpp:278
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition: decl_image.hpp:230
std::vector< ImagePlane > Planes() const noexcept
Access all planes for this image.
Definition: detail_image.hpp:72
bool PlaneDataTypesIdentical() const noexcept
Check if all planes have the same data type.
Definition: decl_image.hpp:237
void * Handle() const noexcept
Classic API image handle.
Definition: decl_image.hpp:223
T X() const noexcept
Gets the x-component of the point.
Definition: point_2d.hpp:86
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:106
Object describing the fringes that are available around images in a sample image list.
Definition: fringes.hpp:23
Collection of image samples.
Definition: sample_image_list.hpp:95
Collection of data samples.
Definition: sample_list.hpp:240
Classifier type that operates on images.
Definition: sample_image_list.hpp:154
int ImageDimension() const
Dimension (# of planes) of the images that can be added to the image list.
Definition: sample_image_list.hpp:248
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:285
Size2D< int > FeatureWindowSize() const
Size of the feature window.
Definition: sample_image_list.hpp:187
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:217
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:264
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:232
Point2D< int > FeatureWindowLocation() const
Location of the feature window (position of left top corner inside the image).
Definition: sample_image_list.hpp:202
Base class for sample lists.
Definition: sample_list.hpp:360
void * Handle() const noexcept
Classic API SIL handle.
Definition: sample_list.hpp:403
T Height() const noexcept
Gets the vertical component of the size.
Definition: size_2d.hpp:79
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
SampleExtractionMode
Possible approaches to the sample extraction in the "Add" methods of image list classes.
Definition: sample_image_list.hpp:28
@ TopLeftCorner
Position parameter is assumed to refer to the top left corner of the feature window.
@ OriginPosition
Position parameter is assumed to refer to the origin of the feature window.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24