OpenCV 4.10.0-dev
Open Source Computer Vision
Loading...
Searching...
No Matches
Structural Analysis and Shape Descriptors

Detailed Description

Enumerations

enum  cv::cuda::MomentsOrder {
  cv::cuda::FIRST_ORDER_MOMENTS = 1 ,
  cv::cuda::SECOND_ORDER_MOMENTS = 2 ,
  cv::cuda::THIRD_ORDER_MOMENTS = 3
}
 Order of image moments. More...
 

Functions

Moments cv::cuda::convertSpatialMoments (Mat spatialMoments, const MomentsOrder order, const int momentsType)
 Converts the spatial image moments returned from cuda::spatialMoments to cv::Moments.
 
Moments cv::cuda::moments (InputArray src, const bool binaryImage=false, const MomentsOrder order=MomentsOrder::THIRD_ORDER_MOMENTS, const int momentsType=CV_64F)
 Calculates all of the moments up to the 3rd order of a rasterized shape.
 
int cv::cuda::numMoments (const MomentsOrder order)
 Returns the number of image moments less than or equal to the largest image moments order.
 
void cv::cuda::spatialMoments (InputArray src, OutputArray moments, const bool binaryImage=false, const MomentsOrder order=MomentsOrder::THIRD_ORDER_MOMENTS, const int momentsType=CV_64F, Stream &stream=Stream::Null())
 Calculates all of the spatial moments up to the 3rd order of a rasterized shape.
 

Enumeration Type Documentation

◆ MomentsOrder

#include <opencv2/cudaimgproc.hpp>

Order of image moments.

Parameters
FIRST_ORDER_MOMENTSFirst order moments
SECOND_ORDER_MOMENTSSecond order moments.
THIRD_ORDER_MOMENTSThird order moments.
Enumerator
FIRST_ORDER_MOMENTS 
SECOND_ORDER_MOMENTS 
THIRD_ORDER_MOMENTS 

Function Documentation

◆ convertSpatialMoments()

Moments cv::cuda::convertSpatialMoments ( Mat spatialMoments,
const MomentsOrder order,
const int momentsType )

#include <opencv2/cudaimgproc.hpp>

Converts the spatial image moments returned from cuda::spatialMoments to cv::Moments.

Parameters
spatialMomentsSpatial moments returned from cuda::spatialMoments.
orderOrder used when calculating image moments with cuda::spatialMoments.
momentsTypePrecision used when calculating image moments with cuda::spatialMoments.
Returns
cv::Moments.
See also
cuda::spatialMoments, cuda::moments, cuda::convertSpatialMoments, cuda::numMoments, cuda::MomentsOrder

◆ moments()

Moments cv::cuda::moments ( InputArray src,
const bool binaryImage = false,
const MomentsOrder order = MomentsOrder::THIRD_ORDER_MOMENTS,
const int momentsType = CV_64F )

#include <opencv2/cudaimgproc.hpp>

Calculates all of the moments up to the 3rd order of a rasterized shape.

The function computes moments, up to the 3rd order, of a rasterized shape. The results are returned in the structure cv::Moments.

Parameters
srcRaster image (single-channel 2D array).
binaryImageIf it is true, all non-zero image pixels are treated as 1's.
orderOrder of largest moments to calculate with lower order moments requiring less computation.
momentsTypePrecision to use when calculating moments. Available types are CV_32F and CV_64F with the performance of CV_32F an order of magnitude greater than CV_64F. If the image is small the accuracy from CV_32F can be equal or very close to CV_64F.
Note
For maximum performance use the asynchronous version cuda::spatialMoments() as this version interally allocates and deallocates both GpuMat and HostMem to respectively perform the calculation on the device and download the result to the host. The costly HostMem allocation cannot be avoided however the GpuMat device allocation can be by using BufferPool, e.g.
setBufferPoolConfig(getDevice(), numMoments(order) * ((momentsType == CV_64F) ? sizeof(double) : sizeof(float)), 1);
#define CV_64F
Definition interface.h:79
int getDevice()
Returns the current device index set by cuda::setDevice or initialized by default.
void setBufferPoolUsage(bool on)
BufferPool management (must be called before Stream creation)
void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount)
int numMoments(const MomentsOrder order)
Returns the number of image moments less than or equal to the largest image moments order.
see the CUDA_TEST_P(Moments, Accuracy) test inside opencv_contrib_source_code/modules/cudaimgproc/test/test_moments.cpp for an example.
Returns
cv::Moments.
See also
cuda::spatialMoments, cuda::convertSpatialMoments, cuda::numMoments, cuda::MomentsOrder

◆ numMoments()

int cv::cuda::numMoments ( const MomentsOrder order)

#include <opencv2/cudaimgproc.hpp>

Returns the number of image moments less than or equal to the largest image moments order.

Parameters
orderOrder of largest moments to calculate with lower order moments requiring less computation.
Returns
number of image moments.
See also
cuda::spatialMoments, cuda::moments, cuda::MomentsOrder

◆ spatialMoments()

void cv::cuda::spatialMoments ( InputArray src,
OutputArray moments,
const bool binaryImage = false,
const MomentsOrder order = MomentsOrder::THIRD_ORDER_MOMENTS,
const int momentsType = CV_64F,
Stream & stream = Stream::Null() )

#include <opencv2/cudaimgproc.hpp>

Calculates all of the spatial moments up to the 3rd order of a rasterized shape.

Asynchronous version of cuda::moments() which only calculates the spatial (not centralized or normalized) moments, up to the 3rd order, of a rasterized shape. Each moment is returned as a column entry in the 1D moments array.

Parameters
srcRaster image (single-channel 2D array).
[out]moments1D array with each column entry containing a spatial image moment.
binaryImageIf it is true, all non-zero image pixels are treated as 1's.
orderOrder of largest moments to calculate with lower order moments requiring less computation.
momentsTypePrecision to use when calculating moments. Available types are CV_32F and CV_64F with the performance of CV_32F an order of magnitude greater than CV_64F. If the image is small the accuracy from CV_32F can be equal or very close to CV_64F.
streamStream for the asynchronous version.
Note
For maximum performance pre-allocate a 1D GpuMat for moments of the correct type and size large enough to store the all the image moments of up to the desired order. e.g. With order === MomentsOrder::SECOND_ORDER_MOMENTS and momentsType == CV_32F moments can be allocated as
Base storage class for GPU memory with reference counting.
Definition cuda.hpp:106
#define CV_32F
Definition interface.h:78
@ SECOND_ORDER_MOMENTS
Definition cudaimgproc.hpp:798
The central and normalized moments can easily be calculated on the host by downloading the moments array and using the cuda::convertSpatialMoments helper function. e.g.
spatialMomentsDevice.download(spatialMomentsHostMem, stream);
stream.waitForCompletion();
Mat spatialMoments = spatialMomentsHostMem.createMatHeader();
n-dimensional dense array class
Definition mat.hpp:829
struct returned by cv::moments
Definition types.hpp:967
Class with reference counting wrapping special memory type allocation functions from CUDA.
Definition cuda.hpp:792
void spatialMoments(InputArray src, OutputArray moments, const bool binaryImage=false, const MomentsOrder order=MomentsOrder::THIRD_ORDER_MOMENTS, const int momentsType=CV_64F, Stream &stream=Stream::Null())
Calculates all of the spatial moments up to the 3rd order of a rasterized shape.
Moments convertSpatialMoments(Mat spatialMoments, const MomentsOrder order, const int momentsType)
Converts the spatial image moments returned from cuda::spatialMoments to cv::Moments.

see the CUDA_TEST_P(Moments, Async) test inside opencv_contrib_source_code/modules/cudaimgproc/test/test_moments.cpp for an example.

See also
cuda::moments, cuda::convertSpatialMoments, cuda::numMoments, cuda::MomentsOrder