7# include "../_cexports/c_foundation.h"
9# include "../global.hpp"
10# include "../image.hpp"
11# include "../value_range.hpp"
12# include "../exception.hpp"
13# include "../point_2d.hpp"
14# include "../rect.hpp"
15# include "../size_2d.hpp"
16# include "../angle.hpp"
99 class BlobAnalyzer final
121 explicit BlobAnalyzer(
const ImagePlane &plane)
123 CExports::
FBlobCreate(plane_.Parent().Handle(), static_cast<CExports::cvbdim_t>(plane_.
Plane())))
126 if (!handle_.Handle())
127 Utilities::SystemInfo::ThrowLastError();
130 void *Handle() const noexcept
132 return handle_.Handle();
135 void SetAOI(Rect<int> aoi)
138 Handle(),
static_cast<CExports::cvbdim_t
>(plane_.Plane()),
static_cast<CExports::cvbdim_t
>(aoi.Left()),
139 static_cast<CExports::cvbdim_t
>(aoi.Top()),
static_cast<CExports::cvbdim_t
>(aoi.Right()),
140 static_cast<CExports::cvbdim_t
>(aoi.Bottom())));
142 Utilities::SystemInfo::ThrowLastError(result);
145 void SetSkipBinarzation(
bool skip)
149 Utilities::SystemInfo::ThrowLastError(result);
157 Utilities::SystemInfo::ThrowLastError(result);
160 void SetSizeFilter(ValueRange<int> sizeFilter)
162 auto result = CVB_CALL_CAPI(
FBlobSetLimitArea(Handle(),
static_cast<CExports::cvbval_t
>(sizeFilter.Min()),
163 static_cast<CExports::cvbval_t
>(sizeFilter.Max())));
165 Utilities::SystemInfo::ThrowLastError(result);
168 void SetWidthFilter(ValueRange<int> widthFilter)
170 auto result = CVB_CALL_CAPI(
FBlobSetLimitWidth(Handle(),
static_cast<CExports::cvbval_t
>(widthFilter.Min()),
171 static_cast<CExports::cvbval_t
>(widthFilter.Max())));
173 Utilities::SystemInfo::ThrowLastError(result);
176 void SetHeightFilter(ValueRange<int> heightFilter)
179 CVB_CALL_CAPI(
FBlobSetLimitHeight(Handle(),
static_cast<CExports::cvbval_t
>(heightFilter.Min()),
180 static_cast<CExports::cvbval_t
>(heightFilter.Max())));
182 Utilities::SystemInfo::ThrowLastError(result);
185 void SetBinarizationRange(ValueRange<int> binarizationRange)
187 auto result = CVB_CALL_CAPI(
189 static_cast<CExports::cvbval_t
>(binarizationRange.Max())));
191 Utilities::SystemInfo::ThrowLastError(result);
194 std::vector<BlobResult> Run();
196 const ImagePlane &plane_;
198 ReleaseObjectGuard handle_;
206 class BlobResult final
208 friend class Internal::BlobAnalyzer;
211 BlobResult() noexcept
221 double X() const noexcept
221 double X() const noexcept {
…}
231 double Y() const noexcept
231 double Y() const noexcept {
…}
274 return minimumMoment_;
285 return maximumMoment_;
315 return minimummomentPoints_;
319 BlobResult(
const Internal::BlobAnalyzer &analyzer,
int index)
noexcept
328 CExports::cvbval_t size = 0;
329 CVB_CALL_CAPI(
FBlobGetSize(analyzer.Handle(), index, size));
330 size_ =
static_cast<double>(size);
332 CExports::cvbdim_t left = 0;
333 CExports::cvbdim_t top = 0;
334 CExports::cvbdim_t width = 0;
335 CExports::cvbdim_t height = 0;
338 Size2D<int>(
static_cast<int>(width),
static_cast<int>(height)));
340 double angleRad = 0.0;
342 FBlobGetMoments(analyzer.Handle(), index, minimumMoment_, maximumMoment_, momentRatio_, angleRad));
345 CExports::cvbval_t x0 = 0;
346 CExports::cvbval_t y0 = 0;
347 CExports::cvbval_t x1 = 0;
348 CExports::cvbval_t y1 = 0;
350 minimummomentPoints_ = {
Point2D<int>(
static_cast<int>(x0),
static_cast<int>(y0)),
351 Point2D<int>(
static_cast<int>(x1),
static_cast<int>(y1))};
357 double minimumMoment_ = 0.0;
358 double maximumMoment_ = 0.0;
359 double momentRatio_ = 0.0;
206 class BlobResult final {
…};
366 auto resutlExec = CExports::FBlobExec(Handle());
368 Utilities::SystemInfo::ThrowLastError(resutlExec);
370 CExports::cvbval_t numBlobs = 0;
371 auto resultNumBlobs = CExports::FBlobGetNumBlobs(Handle(), numBlobs);
373 Utilities::SystemInfo::ThrowLastError(resultNumBlobs);
376 for (
int i = 0; i < static_cast<int>(numBlobs); ++i)
411 return borderFilter_;
421 borderFilter_ = borderFilter;
432 return rangeFilters_.find(rangeFilter) != rangeFilters_.end();
446 return rangeFilters_[rangeFilter];
450 void Apply(Internal::BlobAnalyzer &analyzer)
const
453 analyzer.SetBorderFilter(borderFilter_);
476 Internal::BlobAnalyzer analyzer(plane);
477 analyzer.SetBinarizationRange(binarizationThreshold);
478 return analyzer.Run();
492 Internal::BlobAnalyzer analyzer(plane);
493 analyzer.SetBinarizationRange(binarizationThreshold);
494 analyzer.SetAOI(aoi);
495 return analyzer.Run();
509 Internal::BlobAnalyzer analyzer(plane);
510 analyzer.SetBinarizationRange(binarizationThreshold);
511 filter.Apply(analyzer);
512 return analyzer.Run();
528 Internal::BlobAnalyzer analyzer(plane);
529 analyzer.SetBinarizationRange(binarizationThreshold);
530 analyzer.SetAOI(aoi);
531 filter.Apply(analyzer);
532 return analyzer.Run();
545 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
546 analyzer.SetSkipBinarzation(
true);
547 return analyzer.Run();
561 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
562 analyzer.SetSkipBinarzation(
true);
563 analyzer.SetAOI(aoi);
564 return analyzer.Run();
578 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
579 analyzer.SetSkipBinarzation(
true);
580 filter.Apply(analyzer);
581 return analyzer.Run();
596 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
597 analyzer.SetSkipBinarzation(
true);
598 analyzer.SetAOI(aoi);
599 filter.Apply(analyzer);
600 return analyzer.Run();
Object for convenient and type - safe handling of angles.
Definition angle.hpp:16
static Angle FromRadians(double rad, bool trim=false) noexcept
Create an angle in radians.
Definition angle.hpp:39
Class to build a filter for the blob search.
Definition blob.hpp:386
BlobFilter()=default
Default filter without any filter set.
friend std::vector< BlobResult > BinarizeAndSearchBlobs(const ImagePlane &plane, ValueRange< int > binarizationThreshold, const BlobFilter &filter)
Searches for all blobs in the given image plane.
Definition blob.hpp:507
ValueRange< int > & operator[](BlobRangeFilter rangeFilter)
Sets the range filters via an attribute.
Definition blob.hpp:444
Cvb::Foundation::Blob::BlobBorderFilter BorderFilter() const noexcept
Gets whether to filter blobs that touch the borders of the image.
Definition blob.hpp:409
bool ContainsRangeFilter(BlobRangeFilter rangeFilter) const noexcept
Check if a range filter exists.
Definition blob.hpp:430
void SetBorderFilter(Cvb::Foundation::Blob::BlobBorderFilter borderFilter) noexcept
Sets whether to filter blobs that touch the borders of the image.
Definition blob.hpp:419
friend std::vector< BlobResult > SearchBlobs(const Image &binarizedImage, const BlobFilter &filter)
Searches for all blobs in the given binarized image.
Definition blob.hpp:576
Container for a blob analysis result.
Definition blob.hpp:207
std::vector< Point2D< int > > MinimumMomentPoints() const
Points where the major axis of the blob intersects with the blob's bounding box.
Definition blob.hpp:313
Angle MomentAngle() const noexcept
Angle between Major moment axis and the x-axis.
Definition blob.hpp:303
Point2D< double > Center() const noexcept
Position of the blob's center.
Definition blob.hpp:241
double Size() const noexcept
Size (area) of the blob in pixels.
Definition blob.hpp:251
Rect< int > BoundingBox() const noexcept
Bounding box of the blob.
Definition blob.hpp:261
double Y() const noexcept
Get Y component of the blob center.
Definition blob.hpp:231
double MinimumMoment() const noexcept
Minimum inertial moment (smaller 2nd order moment translated into the blob's major/minor axis coordin...
Definition blob.hpp:272
double X() const noexcept
Get X component of the blob center.
Definition blob.hpp:221
double MomentRatio() const noexcept
Ratio of the minimum moment and the maximum moment of this blob.
Definition blob.hpp:293
double MaximumMoment() const noexcept
Maximum inertial moment (larger 2nd order moments translated into the blob's major/minor axis coordin...
Definition blob.hpp:283
Class to build a filter for the blob search.
Definition blob.hpp:386
Container for a blob analysis result.
Definition blob.hpp:207
The Common Vision Blox image.
Definition decl_image.hpp:45
ImagePlane Plane(int plane) const
Indexed access to the individual plane information.
Definition detail_image.hpp:58
Image plane information container.
Definition decl_image_plane.hpp:29
Plane information container.
Definition decl_plane.hpp:25
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
Rectangle object.
Definition rect.hpp:24
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
Container for range definitions.
Definition value_range.hpp:17
cvbres_t FBlobSetLimitWidth(FBLOB Handle, long Min, long Max)
cvbres_t FBlobSetArea(FBLOB Handle, long Index, long left, long top, long right, long bottom)
cvbres_t FBlobGetCenterEx(FBLOB Handle, long BlobNum, double &CenterX, double &CenterY)
FBLOB FBlobCreate(IMG Image, long Index)
cvbres_t FBlobSetLimitArea(FBLOB Handle, long AreaMin, long AreaMax)
cvbres_t FBlobSetLimitHeight(FBLOB Handle, long Min, long Max)
cvbres_t FBlobGetBoundingBoxEx(FBLOB Handle, long BlobNum, long &x, long &y, long &dx, long &dy)
cvbres_t FBlobSetObjectTouchBorder(FBLOB Handle, long Mask)
cvbres_t FBlobGetSize(FBLOB Handle, long BlobNum, long &Size)
cvbres_t FBlobGetMoments(FBLOB Handle, long BlobNum, double &Min, double &Max, double &Ratio, double &Angle)
cvbres_t FBlobGetMinMomentPointsEx(FBLOB Handle, long BlobNum, long &x0, long &y0, long &x1, long &y1)
cvbres_t FBlobSetSkipBinarization(FBLOB Handle, cvbbool_t Skip)
cvbres_t FBlobSetObjectFeatureRange(FBLOB Handle, long FeatureMin, long FeatureMax)
Blob search methods.
Definition blob.hpp:41
std::vector< BlobResult > BinarizeAndSearchBlobs(const ImagePlane &plane, ValueRange< int > binarizationThreshold)
Searches for all blobs in the given image plane.
Definition blob.hpp:473
BlobBorderFilter
Enumeration for filtering blobs that touch the boundaries of the AOI specified for blob extraction.
Definition blob.hpp:59
@ Bottom
Filter out those blobs that touch the bottom border.
Definition blob.hpp:69
@ None
Do not filter out those blobs that touch a border.
Definition blob.hpp:61
@ Right
Filter out those blobs that touch the right border.
Definition blob.hpp:63
@ Left
Filter out those blobs that touch the left border.
Definition blob.hpp:67
@ Top
Filter out those blobs that touch the top border.
Definition blob.hpp:65
@ All
Filter out those blobs that touch any border.
Definition blob.hpp:71
BlobRangeFilter
Defines the attribute for a blob filter range.
Definition blob.hpp:45
@ Width
Width of the blob in pixels.
Definition blob.hpp:49
@ Size
Area of the blob in pixels.
Definition blob.hpp:47
@ Height
Height of the blob in pixels.
Definition blob.hpp:51
std::vector< BlobResult > SearchBlobs(const Image &binarizedImage)
Searches for all blobs in the given binarized image.
Definition blob.hpp:543
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17