5# include "../_cexports/c_foundation.h"
7# include "../global.hpp"
8# include "../image.hpp"
9# include "../exception.hpp"
10# include "../point_2d.hpp"
11# include "../rect.hpp"
28 inline HandleGuard<Foundation::Moments::ImageMoments>::HandleGuard(
void *handle) noexcept
29 : HandleGuard<Foundation::Moments::ImageMoments>(handle, [](
void *h) { CVB_CALL_CAPI(
ReleaseObject(h)); })
120 , calculationPreference_(preference)
121 , lastOffset_(aoi.Location())
123 auto h = CVB_CALL_CAPI(
CreateImageMoments(
static_cast<CExports::TMomentsCalculation
>(preference)));
126 Utilities::SystemInfo::ThrowLastError();
131 aoi.Top(), aoi.Right(), aoi.Bottom(), h));
141 :
ImageMoments(imagePlane, imagePlane.Parent().Bounds(), preference)
163 return std::make_unique<ImageMoments>(imagePlane, aoi, preference);
176 return std::make_unique<ImageMoments>(imagePlane, preference);
187 return calculationPreference_;
199 return handle_.Handle();
216 offset.
X(), offset.
Y(),
234 return SpatialMoment(xOrder, yOrder, normalization, lastOffset_);
262 double m1, m2, m3, m4, m5, m6, m7;
265 return HuMomentsType{m1, m2, m3, m4, m5, m6, m7};
269 HandleGuard<ImageMoments> handle_;
ImageMoments(const ImagePlane &imagePlane, Rect< int > aoi, MomentsCalculation preference=MomentsCalculation::FavorNone)
Calculate the moments on the input ImagePlane and area of interest.
Definition moments.hpp:117
State object for calculating various image moments.
Definition moments.hpp:108
ImageMoments(const ImagePlane &imagePlane, Rect< int > aoi, MomentsCalculation preference=MomentsCalculation::FavorNone)
Calculate the moments on the input ImagePlane and area of interest.
Definition moments.hpp:117
ImageMoments(const ImagePlane &imagePlane, MomentsCalculation preference=MomentsCalculation::FavorNone)
Calculate the moments on the input imagePlane.
Definition moments.hpp:140
MomentsCalculation CalculationPreference() const noexcept
The preference of speed versus accuracy chosen when this object was created.
Definition moments.hpp:185
static std::unique_ptr< ImageMoments > Calculate(const ImagePlane &imagePlane, MomentsCalculation preference=MomentsCalculation::FavorNone)
Calculate the moments on the input imagePlane.
Definition moments.hpp:173
HuMoments HuMoments()
Get the seven Hu moments of the image.
Definition moments.hpp:260
ImageMoments(ImageMoments &&) noexcept=default
Move constructor.
double SpatialMoment(MomentsOrder xOrder, MomentsOrder yOrder, MomentsNormalization normalization)
Get one of the spatial image moments.
Definition moments.hpp:232
double SpatialMoment(MomentsOrder xOrder, MomentsOrder yOrder, MomentsNormalization normalization, Point2D< int > offset)
Get one of the spatial image moments.
Definition moments.hpp:211
void * Handle() const noexcept
Classic API IMGMOMENTS handle.
Definition moments.hpp:197
double CentralMoment(MomentsOrder xOrder, MomentsOrder yOrder, MomentsNormalization normalization)
Get one of the central image moments.
Definition moments.hpp:246
static std::unique_ptr< ImageMoments > Calculate(const ImagePlane &imagePlane, Rect< int > aoi, MomentsCalculation preference=MomentsCalculation::FavorNone)
Calculate the moments on the input imagePlane and aoi.
Definition moments.hpp:160
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
Image plane information container.
Definition decl_image_plane.hpp:29
int Plane() const noexcept
Plane index in the image, to which this plane refers to.
Definition decl_image_plane.hpp:147
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition detail_image_plane.hpp:87
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
Rectangle object.
Definition rect.hpp:24
cvbres_t CalculateMoments(IMG ImgIn, long Index, long left, long top, long right, long bottom, IMGMOMENTS Moments)
IMGMOMENTS CreateImageMoments(TMomentsCalculation CalcMode)
cvbres_t GetSpatialImageMoment(IMGMOMENTS Moments, cvbval_t XOrder, cvbval_t YOrder, cvbdim_t OffsetX, cvbdim_t OffsetY, cvbbool_t Normalized, double &Moment)
cvbres_t GetHuImageMoments(IMGMOMENTS Moments, double &M1, double &M2, double &M3, double &M4, double &M5, double &M6, double &M7)
cvbres_t GetCentralImageMoment(IMGMOMENTS Moments, long XOrder, long YOrder, cvbbool_t Normalized, double &Moment)
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for image moments related tools from the Foundation package.
Definition moments.hpp:22
MomentsOrder
Enumerated order for x and y central or spatial moments.
Definition moments.hpp:57
@ Order0
0th order
Definition moments.hpp:59
@ Order3
3rd order
Definition moments.hpp:65
@ Order1
1st order
Definition moments.hpp:61
@ Order2
2nd order
Definition moments.hpp:63
std::shared_ptr< ImageMoments > ImageMomentsPtr
Convenience shared pointer for ImageMoments.
Definition moments.hpp:275
MomentsCalculation
Choose between speed and accuracy during image moment calculation.
Definition moments.hpp:46
@ FavorNone
Favor neither speed nor accuracy.
Definition moments.hpp:48
@ FavorSpeed
Favor speed over accuracy during moments calculation.
Definition moments.hpp:50
@ FavorAccuracy
Favor accuracy over speed during moments calculation.
Definition moments.hpp:52
MomentsNormalization
Available normalization modes for moment calculations.
Definition moments.hpp:70
@ Normalized
Report moments normalized.
Definition moments.hpp:74
@ Unnormalized
Report moments unnormalized.
Definition moments.hpp:72
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
Results of Hu Moment calculation.
Definition moments.hpp:81
double M2
Hu Moment M2.
Definition moments.hpp:86
double M5
Hu Moment M5.
Definition moments.hpp:95
double M7
Hu Moment M7.
Definition moments.hpp:101
double M1
Hu Moment M1.
Definition moments.hpp:83
double M6
Hu Moment M6.
Definition moments.hpp:98
double M4
Hu Moment M4.
Definition moments.hpp:92
double M3
Hu Moment M3.
Definition moments.hpp:89