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"
15#include "../size_2d.hpp"
16#include "../angle.hpp"
94class BlobAnalyzer final
96 friend class BlobResult;
97 friend class BlobFilter;
111 explicit BlobAnalyzer(
const ImagePlane& plane)
112 : handle_(CExports::FBlobCreate(plane_.Parent().Handle(), static_cast<CExports::cvbdim_t>(plane_.
Plane())))
115 if (!handle_.Handle())
116 Utilities::SystemInfo::ThrowLastError();
122 void* Handle() const noexcept
124 return handle_.Handle();
127 void SetAOI(Rect<int> aoi)
129 auto result = CVB_CALL_CAPI(FBlobSetArea(Handle(),
130 static_cast<CExports::cvbdim_t
>(plane_.Plane()),
131 static_cast<CExports::cvbdim_t
>(aoi.Left()),
132 static_cast<CExports::cvbdim_t
>(aoi.Top()),
133 static_cast<CExports::cvbdim_t
>(aoi.Right()),
134 static_cast<CExports::cvbdim_t
>(aoi.Bottom())));
136 Utilities::SystemInfo::ThrowLastError(result);
139 void SetSkipBinarzation(
bool skip)
141 auto result = CVB_CALL_CAPI(FBlobSetSkipBinarization(Handle(),
144 Utilities::SystemInfo::ThrowLastError(result);
149 auto result = CVB_CALL_CAPI(FBlobSetObjectTouchBorder(Handle(),
150 static_cast<CExports::cvbval_t
>(borderFilter)));
152 Utilities::SystemInfo::ThrowLastError(result);
155 void SetSizeFilter(ValueRange<int> sizeFilter)
157 auto result = CVB_CALL_CAPI(FBlobSetLimitArea(Handle(),
158 static_cast<CExports::cvbval_t
>(sizeFilter.Min()),
159 static_cast<CExports::cvbval_t
>(sizeFilter.Max())));
161 Utilities::SystemInfo::ThrowLastError(result);
164 void SetWidthFilter(ValueRange<int> widthFilter)
166 auto result = CVB_CALL_CAPI(FBlobSetLimitWidth(Handle(),
167 static_cast<CExports::cvbval_t
>(widthFilter.Min()),
168 static_cast<CExports::cvbval_t
>(widthFilter.Max())));
170 Utilities::SystemInfo::ThrowLastError(result);
173 void SetHeightFilter(ValueRange<int> heightFilter)
175 auto result = CVB_CALL_CAPI(FBlobSetLimitHeight(Handle(),
176 static_cast<CExports::cvbval_t
>(heightFilter.Min()),
177 static_cast<CExports::cvbval_t
>(heightFilter.Max())));
179 Utilities::SystemInfo::ThrowLastError(result);
182 void SetBinarizationRange(ValueRange<int> binarizationRange)
184 auto result = CVB_CALL_CAPI(FBlobSetObjectFeatureRange(Handle(),
185 static_cast<CExports::cvbval_t
>(binarizationRange.Min()),
186 static_cast<CExports::cvbval_t
>(binarizationRange.Max())));
188 Utilities::SystemInfo::ThrowLastError(result);
193 const ImagePlane & plane_;
197 ReleaseObjectGuard handle_;
207 friend class Internal::BlobAnalyzer;
221 double X() const noexcept
231 double Y() const noexcept
273 return minimumMoment_;
283 return maximumMoment_;
313 return minimummomentPoints_;
319 BlobResult(
const Internal::BlobAnalyzer& analyzer,
int index)
noexcept
325 CVB_CALL_CAPI(FBlobGetCenterEx(analyzer.Handle(), index, x, y));
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;
336 CVB_CALL_CAPI(FBlobGetBoundingBoxEx(analyzer.Handle(), index, left, top, width, height));
338 Size2D<int>(
static_cast<int>(width),
static_cast<int>(height)));
340 double angleRad = 0.0;
341 CVB_CALL_CAPI(FBlobGetMoments(analyzer.Handle(), index, minimumMoment_, maximumMoment_, momentRatio_, angleRad));
344 CExports::cvbval_t x0 = 0;
345 CExports::cvbval_t y0 = 0;
346 CExports::cvbval_t x1 = 0;
347 CExports::cvbval_t y1 = 0;
348 CVB_CALL_CAPI(FBlobGetMinMomentPointsEx(analyzer.Handle(), index, x0, y0, x1, y1));
349 minimummomentPoints_ = {
Point2D<int>(
static_cast<int>(x0),
static_cast<int>(y0)),
350 Point2D<int>(
static_cast<int>(x1),
static_cast<int>(y1)) };
356 double minimumMoment_ = 0.0;
357 double maximumMoment_ = 0.0;
358 double momentRatio_ = 0.0;
367 auto resutlExec = CExports::FBlobExec(Handle());
369 Utilities::SystemInfo::ThrowLastError(resutlExec);
371 CExports::cvbval_t numBlobs = 0;
372 auto resultNumBlobs = CExports::FBlobGetNumBlobs(Handle(), numBlobs);
374 Utilities::SystemInfo::ThrowLastError(resultNumBlobs);
377 for (
int i = 0; i < static_cast<int>(numBlobs); ++i)
378 results[i] = BlobResult(*
this, i);
410 return borderFilter_;
420 borderFilter_ = borderFilter;
431 return rangeFilters_.find(rangeFilter) != rangeFilters_.end();
447 return rangeFilters_[rangeFilter];
452 void Apply(Internal::BlobAnalyzer & analyzer)
const
455 analyzer.SetBorderFilter(borderFilter_);
485 Internal::BlobAnalyzer analyzer(plane);
486 analyzer.SetBinarizationRange(binarizationThreshold);
487 return analyzer.Run();
502 Internal::BlobAnalyzer analyzer(plane);
503 analyzer.SetBinarizationRange(binarizationThreshold);
504 analyzer.SetAOI(aoi);
505 return analyzer.Run();
520 Internal::BlobAnalyzer analyzer(plane);
521 analyzer.SetBinarizationRange(binarizationThreshold);
522 filter.Apply(analyzer);
523 return analyzer.Run();
539 Internal::BlobAnalyzer analyzer(plane);
540 analyzer.SetBinarizationRange(binarizationThreshold);
541 analyzer.SetAOI(aoi);
542 filter.Apply(analyzer);
543 return analyzer.Run();
557 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
558 analyzer.SetSkipBinarzation(
true);
559 return analyzer.Run();
573 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
574 analyzer.SetSkipBinarzation(
true);
575 analyzer.SetAOI(aoi);
576 return analyzer.Run();
590 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
591 analyzer.SetSkipBinarzation(
true);
592 filter.Apply(analyzer);
593 return analyzer.Run();
608 Internal::BlobAnalyzer analyzer(binarizedImage.
Plane(0));
609 analyzer.SetSkipBinarzation(
true);
610 analyzer.SetAOI(aoi);
611 filter.Apply(analyzer);
612 return analyzer.Run();
Object for convenient and type - safe handling of angles.
Definition: angle.hpp:19
static Angle FromRadians(double rad, bool trim=false) noexcept
Create an angle in radians.
Definition: angle.hpp:44
Class to build a filter for the blob search.
Definition: blob.hpp:387
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:518
ValueRange< int > & operator[](BlobRangeFilter rangeFilter)
Sets the range filters via an attribute.
Definition: blob.hpp:445
Cvb::Foundation::Blob::BlobBorderFilter BorderFilter() const noexcept
Gets whether to filter blobs that touch the borders of the image.
Definition: blob.hpp:408
bool ContainsRangeFilter(BlobRangeFilter rangeFilter) const noexcept
Check if a range filter exists.
Definition: blob.hpp:429
void SetBorderFilter(Cvb::Foundation::Blob::BlobBorderFilter borderFilter) noexcept
Sets whether to filter blobs that touch the borders of the image.
Definition: blob.hpp:418
friend std::vector< BlobResult > SearchBlobs(const Image &binarizedImage, const BlobFilter &filter)
Searches for all blobs in the given binarized image.
Definition: blob.hpp:588
Container for a blob analysis result.
Definition: blob.hpp:206
std::vector< Point2D< int > > MinimumMomentPoints() const
Points where the major axis of the blob intersects with the blob's bounding box.
Definition: blob.hpp:311
Angle MomentAngle() const noexcept
Angle between Major moment axis and the x-axis.
Definition: blob.hpp:301
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:271
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:291
double MaximumMoment() const noexcept
Maximum inertial moment (larger 2nd order moments translated into the blob's major/minor axis coordin...
Definition: blob.hpp:281
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:65
Image plane information container.
Definition: decl_image_plane.hpp:33
Plane information container.
Definition: decl_plane.hpp:28
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
std::vector< BlobResult > BinarizeAndSearchBlobs(const ImagePlane &plane, ValueRange< int > binarizationThreshold)
Searches for all blobs in the given image plane.
Definition: blob.hpp:483
BlobBorderFilter
Enumeration for filtering blobs that touch the boundaries of the AOI specified for blob extraction.
Definition: blob.hpp:59
@ None
Do not filter out those blobs that touch a border.
BlobRangeFilter
Defines the attribute for a blob filter range.
Definition: blob.hpp:45
@ Width
Width of the blob in pixels.
@ Size
Area of the blob in pixels.
@ Height
Height of the blob in pixels.
std::vector< BlobResult > SearchBlobs(const Image &binarizedImage)
Searches for all blobs in the given binarized image.
Definition: blob.hpp:555
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24