Structural Analysis and Shape Descriptors#
Detailed Description#
Enumerations#
Order of image moments. View details
Enumeration Type Documentation#
MomentsOrder#
#include <opencv2/cudaimgproc.hpp>
Order of image moments.
Enumerator:
|
|
|
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.
See also
cuda::spatialMoments, cuda::moments, cuda::convertSpatialMoments, cuda::numMoments, cuda::MomentsOrder
Parameters
spatialMoments— Spatial moments returned from cuda::spatialMoments.order— Order used when calculating image moments with cuda::spatialMoments.momentsType— Precision used when calculating image moments with cuda::spatialMoments.
Returns
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.
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.
setBufferPoolUsage(true);
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.
Parameters
src— Raster image (single-channel 2D array).binaryImage— If it is true, all non-zero image pixels are treated as 1’s.order— Order of largest moments to calculate with lower order moments requiring less computation.momentsType— Precision 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.
Returns
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.
See also
Parameters
order— Order of largest moments to calculate with lower order moments requiring less computation.
Returns
number of image moments.
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.
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
GpuMat momentsDevice(1,numMoments(MomentsOrder::SECOND_ORDER_MOMENTS),CV_32F)
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.
HostMem spatialMomentsHostMem(1, numMoments(MomentsOrder::SECOND_ORDER_MOMENTS), CV_32F);
spatialMomentsDevice.download(spatialMomentsHostMem, stream);
stream.waitForCompletion();
Mat spatialMoments = spatialMomentsHostMem.createMatHeader();
cv::Moments cvMoments = convertSpatialMoments<float>(spatialMoments, order);
see the CUDA_TEST_P(Moments, Async) test inside opencv_contrib_source_code/modules/cudaimgproc/test/test_moments.cpp for an example.
Parameters
src— Raster image (single-channel 2D array).moments— 1D array with each column entry containing a spatial image moment.binaryImage— If it is true, all non-zero image pixels are treated as 1’s.order— Order of largest moments to calculate with lower order moments requiring less computation.momentsType— Precision 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.stream— Stream for the asynchronous version.