OpenCV  4.9.0
Open Source Computer Vision
Enumerations | Functions
Structural Analysis and Shape Descriptors

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::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. More...
 
int cv::cuda::numMoments (const MomentsOrder order)
 Returns the number of image moments less than or equal to the largest image moments order. More...
 
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. More...
 

Detailed Description

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

◆ 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);
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

◆ 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::moments, cuda::spatialMoments, 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 The central and normalized moments can easily be calculated on the host by downloading the moments array and using the cv::Moments constructor. e.g.
momentsDevice.download(momentsHostMem, stream);
stream.waitForCompletion();
Mat momentsMat = momentsHostMem.createMatHeader();
cv::Moments cvMoments(momentsMat.at<float>(0), momentsMat.at<float>(1), momentsMat.at<float>(2), momentsMat.at<float>(3), momentsMat.at<float>(4), momentsMat.at<float>(5), momentsMat.at<float>(6), momentsMat.at<float>(7), momentsMat.at<float>(8), momentsMat.at<float>(9));
see the CUDA_TEST_P(Moments, Async) test inside opencv_contrib_source_code/modules/cudaimgproc/test/test_moments.cpp for an example.
Returns
cv::Moments.
See also
cuda::moments