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"
108 class BlobAnalyzer final
130 explicit BlobAnalyzer(
const ImagePlane &plane)
132 CExports::
FBlobCreate(plane_.Parent().Handle(), static_cast<CExports::cvbdim_t>(plane_.
Plane())))
135 if (!handle_.Handle())
136 Utilities::SystemInfo::ThrowLastError();
139 void *Handle() const noexcept
141 return handle_.Handle();
144 void SetAOI(Rect<int> aoi)
147 Handle(),
static_cast<CExports::cvbdim_t
>(plane_.Plane()),
static_cast<CExports::cvbdim_t
>(aoi.Left()),
148 static_cast<CExports::cvbdim_t
>(aoi.Top()),
static_cast<CExports::cvbdim_t
>(aoi.Right()),
149 static_cast<CExports::cvbdim_t
>(aoi.Bottom())));
151 Utilities::SystemInfo::ThrowLastError(result);
154 void SetSkipBinarzation(
bool skip)
158 Utilities::SystemInfo::ThrowLastError(result);
166 Utilities::SystemInfo::ThrowLastError(result);
169 void SetSizeFilter(ValueRange<int> sizeFilter)
171 auto result = CVB_CALL_CAPI(
FBlobSetLimitArea(Handle(),
static_cast<CExports::cvbval_t
>(sizeFilter.Min()),
172 static_cast<CExports::cvbval_t
>(sizeFilter.Max())));
174 Utilities::SystemInfo::ThrowLastError(result);
177 void SetWidthFilter(ValueRange<int> widthFilter)
179 auto result = CVB_CALL_CAPI(
FBlobSetLimitWidth(Handle(),
static_cast<CExports::cvbval_t
>(widthFilter.Min()),
180 static_cast<CExports::cvbval_t
>(widthFilter.Max())));
182 Utilities::SystemInfo::ThrowLastError(result);
185 void SetHeightFilter(ValueRange<int> heightFilter)
188 CVB_CALL_CAPI(
FBlobSetLimitHeight(Handle(),
static_cast<CExports::cvbval_t
>(heightFilter.Min()),
189 static_cast<CExports::cvbval_t
>(heightFilter.Max())));
191 Utilities::SystemInfo::ThrowLastError(result);
194 void SetBinarizationRange(ValueRange<int> binarizationRange)
196 auto result = CVB_CALL_CAPI(
198 static_cast<CExports::cvbval_t
>(binarizationRange.Max())));
200 Utilities::SystemInfo::ThrowLastError(result);
203 std::vector<BlobResult> Run();
205 const ImagePlane &plane_;
207 ReleaseObjectGuard handle_;
215 class BlobResult final
217 friend class Internal::BlobAnalyzer;
220 BlobResult() noexcept
230 double X() const noexcept
230 double X() const noexcept {
…}
240 double Y() const noexcept
240 double Y() const noexcept {
…}
283 return minimumMoment_;
294 return maximumMoment_;
324 return minimummomentPoints_;
328 BlobResult(
const Internal::BlobAnalyzer &analyzer,
int index)
noexcept
337 CExports::cvbval_t size = 0;
338 CVB_CALL_CAPI(
FBlobGetSize(analyzer.Handle(), index, size));
339 size_ =
static_cast<double>(size);
341 CExports::cvbdim_t left = 0;
342 CExports::cvbdim_t top = 0;
343 CExports::cvbdim_t width = 0;
344 CExports::cvbdim_t height = 0;
347 Size2D<int>(
static_cast<int>(width),
static_cast<int>(height)));
349 double angleRad = 0.0;
351 FBlobGetMoments(analyzer.Handle(), index, minimumMoment_, maximumMoment_, momentRatio_, angleRad));
354 CExports::cvbval_t x0 = 0;
355 CExports::cvbval_t y0 = 0;
356 CExports::cvbval_t x1 = 0;
357 CExports::cvbval_t y1 = 0;
359 minimummomentPoints_ = {
Point2D<int>(
static_cast<int>(x0),
static_cast<int>(y0)),
360 Point2D<int>(
static_cast<int>(x1),
static_cast<int>(y1))};
366 double minimumMoment_ = 0.0;
367 double maximumMoment_ = 0.0;
368 double momentRatio_ = 0.0;
215 class BlobResult final {
…};
375 auto resutlExec = CExports::FBlobExec(Handle());
377 Utilities::SystemInfo::ThrowLastError(resutlExec);
379 CExports::cvbval_t numBlobs = 0;
380 auto resultNumBlobs = CExports::FBlobGetNumBlobs(Handle(), numBlobs);
382 Utilities::SystemInfo::ThrowLastError(resultNumBlobs);
385 for (
int i = 0; i < static_cast<int>(numBlobs); ++i)
420 return borderFilter_;
430 borderFilter_ = borderFilter;
441 return rangeFilters_.find(rangeFilter) != rangeFilters_.end();
455 return rangeFilters_[rangeFilter];
459 void Apply(Internal::BlobAnalyzer &analyzer)
const
462 analyzer.SetBorderFilter(borderFilter_);
485 Internal::BlobAnalyzer analyzer(plane);
486 analyzer.SetBinarizationRange(binarizationThreshold);
487 return analyzer.Run();
501 Internal::BlobAnalyzer analyzer(plane);
502 analyzer.SetBinarizationRange(binarizationThreshold);
503 analyzer.SetAOI(aoi);
504 return analyzer.Run();
518 Internal::BlobAnalyzer analyzer(plane);
519 analyzer.SetBinarizationRange(binarizationThreshold);
520 filter.Apply(analyzer);
521 return analyzer.Run();
537 Internal::BlobAnalyzer analyzer(plane);
538 analyzer.SetBinarizationRange(binarizationThreshold);
539 analyzer.SetAOI(aoi);
540 filter.Apply(analyzer);
541 return analyzer.Run();
554 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
555 analyzer.SetSkipBinarzation(
true);
556 return analyzer.Run();
570 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
571 analyzer.SetSkipBinarzation(
true);
572 analyzer.SetAOI(aoi);
573 return analyzer.Run();
587 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
588 analyzer.SetSkipBinarzation(
true);
589 filter.Apply(analyzer);
590 return analyzer.Run();
605 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
606 analyzer.SetSkipBinarzation(
true);
607 analyzer.SetAOI(aoi);
608 filter.Apply(analyzer);
609 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:395
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:516
ValueRange< int > & operator[](BlobRangeFilter rangeFilter)
Sets the range filters via an attribute.
Definition blob.hpp:453
Cvb::Foundation::Blob::BlobBorderFilter BorderFilter() const noexcept
Gets whether to filter blobs that touch the borders of the image.
Definition blob.hpp:418
bool ContainsRangeFilter(BlobRangeFilter rangeFilter) const noexcept
Check if a range filter exists.
Definition blob.hpp:439
void SetBorderFilter(Cvb::Foundation::Blob::BlobBorderFilter borderFilter) noexcept
Sets whether to filter blobs that touch the borders of the image.
Definition blob.hpp:428
friend std::vector< BlobResult > SearchBlobs(const Image &binarizedImage, const BlobFilter &filter)
Searches for all blobs in the given binarized image.
Definition blob.hpp:585
Container for a blob analysis result.
Definition blob.hpp:216
std::vector< Point2D< int > > MinimumMomentPoints() const
Points where the major axis of the blob intersects with the blob's bounding box.
Definition blob.hpp:322
Angle MomentAngle() const noexcept
Angle between Major moment axis and the x-axis.
Definition blob.hpp:312
Point2D< double > Center() const noexcept
Position of the blob's center.
Definition blob.hpp:250
double Size() const noexcept
Size (area) of the blob in pixels.
Definition blob.hpp:260
Rect< int > BoundingBox() const noexcept
Bounding box of the blob.
Definition blob.hpp:270
double Y() const noexcept
Get Y component of the blob center.
Definition blob.hpp:240
double MinimumMoment() const noexcept
Minimum inertial moment (smaller 2nd order moment translated into the blob's major/minor axis coordin...
Definition blob.hpp:281
double X() const noexcept
Get X component of the blob center.
Definition blob.hpp:230
double MomentRatio() const noexcept
Ratio of the minimum moment and the maximum moment of this blob.
Definition blob.hpp:302
double MaximumMoment() const noexcept
Maximum inertial moment (larger 2nd order moments translated into the blob's major/minor axis coordin...
Definition blob.hpp:292
Class to build a filter for the blob search.
Definition blob.hpp:395
Container for a blob analysis result.
Definition blob.hpp:216
The Common Vision Blox image.
Definition decl_image.hpp:50
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:50
std::vector< BlobResult > BinarizeAndSearchBlobs(const ImagePlane &plane, ValueRange< int > binarizationThreshold)
Searches for all blobs in the given image plane.
Definition blob.hpp:482
BlobBorderFilter
Enumeration for filtering blobs that touch the boundaries of the AOI specified for blob extraction.
Definition blob.hpp:68
@ Bottom
Filter out those blobs that touch the bottom border.
Definition blob.hpp:78
@ None
Do not filter out those blobs that touch a border.
Definition blob.hpp:70
@ Right
Filter out those blobs that touch the right border.
Definition blob.hpp:72
@ Left
Filter out those blobs that touch the left border.
Definition blob.hpp:76
@ Top
Filter out those blobs that touch the top border.
Definition blob.hpp:74
@ All
Filter out those blobs that touch any border.
Definition blob.hpp:80
BlobRangeFilter
Defines the attribute for a blob filter range.
Definition blob.hpp:54
@ Width
Width of the blob in pixels.
Definition blob.hpp:58
@ Size
Area of the blob in pixels.
Definition blob.hpp:56
@ Height
Height of the blob in pixels.
Definition blob.hpp:60
std::vector< BlobResult > SearchBlobs(const Image &binarizedImage)
Searches for all blobs in the given binarized image.
Definition blob.hpp:552
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