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 = 0, height = 0, dimension = 0;
43 CExports::cvbdatatype_t type = 0;
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 = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
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()));
106 return GetImage (dataHandle);
116template <
class TLabel>
120 ImageLabelInfo (
const SharedReleaseObjectGuard &sguardSil,
const TLabel &label)
121 : label_(label), samples_(std::make_shared<ImageCollection>(sguardSil))
124 ImageLabelInfo (
const ImageLabelInfo& other) =
delete;
125 ImageLabelInfo& operator= (
const ImageLabelInfo& other) =
delete;
126 ImageLabelInfo(ImageLabelInfo&& other) =
delete;
127 ImageLabelInfo& operator= (ImageLabelInfo&& other) =
delete;
128 virtual ~ImageLabelInfo() =
default;
131 using LabelType = TLabel;
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));
173 return SampleDatabase::Fringes(
static_cast<int>(left),
static_cast<int>(top),
static_cast<int>(right),
static_cast<int>(bottom));
183 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
185 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
186 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
188 return Size2D<int>(
static_cast<int>(width),
static_cast<int>(height));
198 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
200 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
201 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
203 return Point2D<int>(
static_cast<int>(left),
static_cast<int>(top));
213 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
215 CExports::cvbdim_t left = 0, top = 0, width = 0, height = 0, originX = 0, originY = 0;
216 CVB_CALL_CAPI_CHECKED(SilGetFeatureWindow(datatype, left, top, width, height, originX, originY));
218 return Point2D<int>(
static_cast<int>(originX),
static_cast<int>(originY));
228 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
230 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
231 CExports::cvbdatatype_t type = 0;
232 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
234 return Size2D<int>(
static_cast<int>(width),
static_cast<int>(height));
244 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
246 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
247 CExports::cvbdatatype_t type = 0;
248 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
250 return static_cast<int>(dimension);
260 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
262 CExports::cvbdim_t width = 0, height = 0, dimension = 0;
263 CExports::cvbdatatype_t type = 0;
264 CVB_CALL_CAPI_CHECKED(SilGetImageDataGeometry(datatype, width, height, dimension, type));
281 auto datatype = CVB_CALL_CAPI(SilGetDataType(
Handle()));
283 CVB_CALL_CAPI_CHECKED(SilSetFeatureWindow(datatype, location.
X(), location.
Y(), size.
Width(), size.
Height(), origin.
X(), origin.
Y()));
298 if (!img.PlaneDataTypesIdentical())
307 if (img.Width() < imageSize.Width())
311 if (img.Height() < imageSize.Height())
327 return Internal::DoBoolCallObjectOut<Image>([&](
void* & resimg)
329 auto dataHandle = CVB_CALL_CAPI (SilGetData(
Handle(), sampleIndex));
330 CVB_CALL_CAPI_CHECKED(SilGetImageData (dataHandle, resimg));
331 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:288
int Height() const noexcept
Height of the image in pixels.
Definition: decl_image.hpp:281
int PlanesCount() const noexcept
Get the number of planes for this image.
Definition: decl_image.hpp:233
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:240
void * Handle() const noexcept
Classic API image handle.
Definition: decl_image.hpp:226
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:97
Collection of data samples.
Definition: sample_list.hpp:243
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:242
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:279
Size2D< int > FeatureWindowSize() const
Size of the feature window.
Definition: sample_image_list.hpp:181
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:292
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:211
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:258
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:325
Size2D< int > ImageSize() const
Size of the images (in pixels) that can be added to the image list.
Definition: sample_image_list.hpp:226
Point2D< int > FeatureWindowLocation() const
Location of the feature window (position of left top corner inside the image).
Definition: sample_image_list.hpp:196
Base class for sample lists.
Definition: sample_list.hpp:364
void * Handle() const noexcept
Classic API SIL handle.
Definition: sample_list.hpp:413
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