| OpenCV 5.0.0alpha Open Source Computer Vision

Loading...
Searching...
No Matches
Enumerations | Functions
Structural Analysis and Shape Descriptors
CUDA-accelerated Computer Vision » Image Processing

## 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

enum cv::cuda::MomentsOrder

`#include <opencv2/cudaimgproc.hpp>`

Order of image moments.

Parameters

  FIRST_ORDER_MOMENTS | First order moments
  SECOND_ORDER_MOMENTS | Second order moments.
  THIRD_ORDER_MOMENTS | Third 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

  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
  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

  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.

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);
  CV_64F
  #define CV_64F
  Definition interface.h:82
  cv::cuda::getDevice
  int getDevice()
  Returns the current device index set by cuda::setDevice or initialized by default.
  cv::cuda::setBufferPoolUsage
  void setBufferPoolUsage(bool on)
  BufferPool management (must be called before Stream creation)
  cv::cuda::setBufferPoolConfig
  void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount)
  cv::cuda::numMoments
  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

  order | Order 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

  | src | Raster image (single-channel 2D array).
  [out] | 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.

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)
  cv::cuda::GpuMat
  Base storage class for GPU memory with reference counting.
  Definition cuda.hpp:106
  CV_32F
  #define CV_32F
  Definition interface.h:81
  cv::cuda::SECOND_ORDER_MOMENTS
  @ 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.
  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);
  cv::Mat
  n-dimensional dense array class
  Definition mat.hpp:951
  cv::Moments
  struct returned by cv::moments
  Definition types.hpp:971
  cv::cuda::HostMem
  Class with reference counting wrapping special memory type allocation functions from CUDA.
  Definition cuda.hpp:791
  cv::cuda::spatialMoments
  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.
  cv::cuda::convertSpatialMoments
  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