Image Processing

gpu::meanShiftFiltering

C++: void gpu::meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr, TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1))

Performs mean-shift filtering for each point of the source image. It maps each point of the source image into another point. As a result, you have a new color and new position of each point.

Parameters:
  • src – Source image. Only CV_8UC4 images are supported for now.
  • dst – Destination image containing the color of mapped points. It has the same size and type as src .
  • sp – Spatial window radius.
  • sr – Color window radius.
  • criteria – Termination criteria. See TermCriteria.

gpu::meanShiftProc

C++: void gpu::meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr, TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1))

Performs a mean-shift procedure and stores information about processed points (their colors and positions) in two images.

Parameters:
  • src – Source image. Only CV_8UC4 images are supported for now.
  • dstr – Destination image containing the color of mapped points. The size and type is the same as src .
  • dstsp – Destination image containing the position of mapped points. The size is the same as src size. The type is CV_16SC2.
  • sp – Spatial window radius.
  • sr – Color window radius.
  • criteria – Termination criteria. See TermCriteria.

gpu::meanShiftSegmentation

C++: void gpu::meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize, TermCriteria criteria=TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1))

Performs a mean-shift segmentation of the source image and eliminates small segments.

Parameters:
  • src – Source image. Only CV_8UC4 images are supported for now.
  • dst – Segmented image with the same size and type as src .
  • sp – Spatial window radius.
  • sr – Color window radius.
  • minsize – Minimum segment size. Smaller segements are merged.
  • criteria – Termination criteria. See TermCriteria.

gpu::integral

C++: void gpu::integral(const GpuMat& src, GpuMat& sum)
C++: void gpu::integral(const GpuMat& src, GpuMat& sum, GpuMat& sqsum)

Computes an integral image and a squared integral image.

Parameters:
  • src – Source image. Only CV_8UC1 images are supported for now.
  • sum – Integral image containing 32-bit unsigned integer values packed into CV_32SC1 .
  • sqsum – Squared integral image of the CV_32FC1 type.

See also

integral()

gpu::sqrIntegral

C++: void gpu::sqrIntegral(const GpuMat& src, GpuMat& sqsum)

Computes a squared integral image.

Parameters:
  • src – Source image. Only CV_8UC1 images are supported for now.
  • sqsum – Squared integral image containing 64-bit unsigned integer values packed into CV_64FC1 .

gpu::columnSum

C++: void gpu::columnSum(const GpuMat& src, GpuMat& sum)

Computes a vertical (column) sum.

Parameters:
  • src – Source image. Only CV_32FC1 images are supported for now.
  • sum – Destination image of the CV_32FC1 type.

gpu::cornerHarris

C++: void gpu::cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType=BORDER_REFLECT101)

Computes the Harris cornerness criteria at each image pixel.

Parameters:
  • src – Source image. Only CV_8UC1 and CV_32FC1 images are supported for now.
  • dst – Destination image containing cornerness values. It has the same size as src and CV_32FC1 type.
  • blockSize – Neighborhood size.
  • ksize – Aperture parameter for the Sobel operator.
  • k – Harris detector free parameter.
  • borderType – Pixel extrapolation method. Only BORDER_REFLECT101 and BORDER_REPLICATE are supported for now.

See also

cornerHarris()

gpu::cornerMinEigenVal

C++: void gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101)

Computes the minimum eigen value of a 2x2 derivative covariation matrix at each pixel (the cornerness criteria).

Parameters:
  • src – Source image. Only CV_8UC1 and CV_32FC1 images are supported for now.
  • dst – Destination image containing cornerness values. The size is the same. The type is CV_32FC1.
  • blockSize – Neighborhood size.
  • ksize – Aperture parameter for the Sobel operator.
  • k – Harris detector free parameter.
  • borderType – Pixel extrapolation method. Only BORDER_REFLECT101 and BORDER_REPLICATE are supported for now.

gpu::mulSpectrums

C++: void gpu::mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false)

Performs a per-element multiplication of two Fourier spectrums.

Parameters:
  • a – First spectrum.
  • b – Second spectrum with the same size and type as a .
  • c – Destination spectrum.
  • flags – Mock parameter used for CPU/GPU interfaces similarity.
  • conjB – Optional flag to specify if the second spectrum needs to be conjugated before the multiplication.

Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.

See also

mulSpectrums()

gpu::mulAndScaleSpectrums

C++: void gpu::mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB=false)

Performs a per-element multiplication of two Fourier spectrums and scales the result.

Parameters:
  • a – First spectrum.
  • b – Second spectrum with the same size and type as a .
  • c – Destination spectrum.
  • flags – Mock parameter used for CPU/GPU interfaces similarity.
  • scale – Scale constant.
  • conjB – Optional flag to specify if the second spectrum needs to be conjugated before the multiplication.

Only full (not packed) CV_32FC2 complex spectrums in the interleaved format are supported for now.

See also

mulSpectrums()

gpu::dft

C++: void gpu::dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags=0)

Performs a forward or inverse discrete Fourier transform (1D or 2D) of the floating point matrix. Use to handle real matrices (CV32FC1) and complex matrices in the interleaved format (CV32FC2).

Parameters:
  • src – Source matrix (real or complex).
  • dst – Destination matrix (real or complex).
  • dft_size – Size of a discrete Fourier transform.
  • flags

    Optional flags:

    • DFT_ROWS transforms each individual row of the source matrix.
    • DFT_SCALE scales the result: divide it by the number of elements in the transform (obtained from dft_size ).
    • DFT_INVERSE inverts DFT. Use for complex-complex cases (real-complex and complex-real cases are always forward and inverse, respectively).
    • DFT_REAL_OUTPUT specifies the output as real. The source matrix is the result of real-complex transform, so the destination matrix must be real.

The source matrix should be continuous, otherwise reallocation and data copying is performed. The function chooses an operation mode depending on the flags, size, and channel count of the source matrix:

  • If the source matrix is complex and the output is not specified as real, the destination matrix is complex and has the dft_size size and CV_32FC2 type. The destination matrix contains a full result of the DFT (forward or inverse).
  • If the source matrix is complex and the output is specified as real, the function assumes that its input is the result of the forward transform (see the next item). The destionation matrix has the dft_size size and CV_32FC1 type. It contains the result of the inverse DFT.
  • If the source matrix is real (its type is CV_32FC1 ), forward DFT is performed. The result of the DFT is packed into complex ( CV_32FC2 ) matrix. So, the width of the destination matrix is dft_size.width / 2 + 1 . But if the source is a single column, the height is reduced instead of the width.

See also

dft()

gpu::convolve

C++: void gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr=false)
C++: void gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr, ConvolveBuf& buf)

Computes a convolution (or cross-correlation) of two images.

Parameters:
  • image – Source image. Only CV_32FC1 images are supported for now.
  • templ – Template image. The size is not greater than the image size. The type is the same as image .
  • result – Result image. The size and type is the same as image .
  • ccorr – Flags to evaluate cross-correlation instead of convolution.
  • buf – Optional buffer to avoid extra memory allocations (for many calls with the same sizes).

gpu::ConvolveBuf

class gpu::ConvolveBuf

Class providing a memory buffer for the gpu::convolve() function.

struct CV_EXPORTS ConvolveBuf
{
    ConvolveBuf() {}
    ConvolveBuf(Size image_size, Size templ_size)
        { create(image_size, templ_size); }
    void create(Size image_size, Size templ_size);

private:
    // Hidden
};

gpu::ConvolveBuf::ConvolveBuf

C++: ConvolveBuf::ConvolveBuf()

Constructs an empty buffer that is properly resized after the first call of the gpu::convolve() function.

C++: ConvolveBuf::ConvolveBuf(Size image_size, Size templ_size)

Constructs a buffer for the gpu::convolve() function with respective arguments.

gpu::matchTemplate

C++: void gpu::matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method)

Computes a proximity map for a raster template and an image where the template is searched for.

Parameters:
  • image – Source image. CV_32F and CV_8U depth images (1..4 channels) are supported for now.
  • templ – Template image with the size and type the same as image .
  • result – Map containing comparison results ( CV_32FC1 ). If image is W x H and templ is w x h, then result must be W-w+1 x H-h+1.
  • method – Specifies the way to compare the template with the image.

The following methods are supported for the CV_8U depth images for now:

  • CV_TM_SQDIFF
  • CV_TM_SQDIFF_NORMED
  • CV_TM_CCORR
  • CV_TM_CCORR_NORMED
  • CV_TM_CCOEFF
  • CV_TM_CCOEFF_NORMED

The following methods are supported for the CV_32F images for now:

  • CV_TM_SQDIFF
  • CV_TM_CCORR

See also

matchTemplate()

gpu::remap

C++: void gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap)

Applies a generic geometrical transformation to an image.

Parameters:
  • src – Source image. Only CV_8UC1 and CV_8UC3 source types are supported.
  • dst – Destination image with the size the same as xmap and the type the same as src .
  • xmap – X values. Only CV_32FC1 type is supported.
  • ymap – Y values. Only CV_32FC1 type is supported.

The function transforms the source image using the specified map:

\texttt{dst} (x,y) =  \texttt{src} (xmap(x,y), ymap(x,y))

Values of pixels with non-integer coordinates are computed using the bilinear interpolation.

See also

remap()

gpu::cvtColor

C++: void gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn=0)
C++: void gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream)

Converts an image from one color space to another.

Parameters:
  • src – Source image with CV_8U, CV_16U, or CV_32F depth and 1, 3, or 4 channels.
  • dst – Destination image with the same size and depth as src .
  • code – Color space conversion code. For details, see cvtColor() . Conversion to/from Luv and Bayer color spaces is not supported.
  • dcn – Number of channels in the destination image. If the parameter is 0, the number of the channels is derived automatically from src and the code .
  • stream – Stream for the asynchronous version.

3-channel color spaces (like HSV, XYZ, and so on) can be stored in a 4-channel image for better perfomance.

See also

cvtColor()

gpu::threshold

C++: double gpu::threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type)
C++: double gpu::threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, const Stream& stream)

Applies a fixed-level threshold to each array element.

Parameters:
  • src – Source array (single-channel). CV_64F depth is not supported.
  • dst – Destination array with the same size and type as src .
  • thresh – Threshold value.
  • maxVal – Maximum value to use with THRESH_BINARY and THRESH_BINARY_INV threshold types.
  • thresholdType – Threshold type. For details, see threshold() . The THRESH_OTSU threshold type is not supported.
  • stream – Stream for the asynchronous version.

See also

threshold()

gpu::resize

C++: void gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)

Resizes an image.

Parameters:
  • src – Source image. CV_8UC1 and CV_8UC4 types are supported.
  • dst – Destination image with the same type as src . The size is dsize (when it is non-zero) or the size is computed from src.size(), fx, and fy .
  • dsize

    Destination image size. If it is zero, it is computed as:

    \texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}

    Either dsize or both fx and fy must be non-zero.

  • fx

    Scale factor along the horizontal axis. If it is zero, it is computed as:

    \texttt{(double)dsize.width/src.cols}

  • fy

    Scale factor along the vertical axis. If it is zero, it is computed as:

    \texttt{(double)dsize.height/src.rows}

  • interpolation – Interpolation method. Only INTER_NEAREST and INTER_LINEAR are supported.

See also

resize()

gpu::warpAffine

C++: void gpu::warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR)

Applies an affine transformation to an image.

Parameters:
  • src – Source image. CV_8U, CV_16U, CV_32S, or CV_32F depth and 1, 3, or 4 channels are supported.
  • dst – Destination image with the same type as src . The size is dsize .
  • M2x3 transformation matrix.
  • dsize – Size of the destination image.
  • flags – Combination of interpolation methods (see resize()) and the optional flag WARP_INVERSE_MAP specifying that M is an inverse transformation (dst=>src). Only INTER_NEAREST, INTER_LINEAR, and INTER_CUBIC interpolation methods are supported.

See also

warpAffine()

gpu::warpPerspective

C++: void gpu::warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR)

Applies a perspective transformation to an image.

Parameters:
  • src – Source image. CV_8U, CV_16U, CV_32S, or CV_32F depth and 1, 3, or 4 channels are supported.
  • dst – Destination image with the same type as src . The size is dsize .
  • M3x3 transformation matrix.
  • dsize – Size of the destination image.
  • flags – Combination of interpolation methods (see resize() ) and the optional flag WARP_INVERSE_MAP specifying that M is the inverse transformation (dst => src). Only INTER_NEAREST, INTER_LINEAR, and INTER_CUBIC interpolation methods are supported.

gpu::rotate

C++: void gpu::rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift=0, double yShift=0, int interpolation=INTER_LINEAR)

Rotates an image around the origin (0,0) and then shifts it.

Parameters:
  • src – Source image. CV_8UC1 and CV_8UC4 types are supported.
  • dst – Destination image with the same type as src . The size is dsize .
  • dsize – Size of the destination image.
  • angle – Angle of rotation in degrees.
  • xShift – Shift along the horizontal axis.
  • yShift – Shift along the vertical axis.
  • interpolation – Interpolation method. Only INTER_NEAREST, INTER_LINEAR, and INTER_CUBIC are supported.

gpu::copyMakeBorder

C++: void gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, const Scalar& value=Scalar())

Copies a 2D array to a larger destination array and pads borders with the given constant.

Parameters:
  • src – Source image. CV_8UC1, CV_8UC4, CV_32SC1, and CV_32FC1 types are supported.
  • dst – Destination image with the same type as src. The size is Size(src.cols+left+right, src.rows+top+bottom) .
  • top
  • bottom
  • left
  • right – Number of pixels in each direction from the source image rectangle to extrapolate. For example: top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built.
  • value – Border value.

See also

copyMakeBorder()

gpu::rectStdDev

C++: void gpu::rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect)

Computes a standard deviation of integral images.

Parameters:
  • src – Source image. Only the CV_32SC1 type is supported.
  • sqr – Squared source image. Only the CV_32FC1 type is supported.
  • dst – Destination image with the same type and size as src .
  • rect – Rectangular window.

gpu::evenLevels

C++: void gpu::evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel)

Computes levels with even distribution.

Parameters:
  • levels – Destination array. levels has 1 row, nLevels columns, and the CV_32SC1 type.
  • nLevels – Number of computed levels. nLevels must be at least 2.
  • lowerLevel – Lower boundary value of the lowest level.
  • upperLevel – Upper boundary value of the greatest level.

gpu::histEven

C++: void gpu::histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel)
C++: void gpu::histEven(const GpuMat& src, GpuMat* hist, int* histSize, int* lowerLevel, int* upperLevel)

Calculates a histogram with evenly distributed bins.

Parameters:
  • src – Source image. CV_8U, CV_16U, or CV_16S depth and 1 or 4 channels are supported. For a four-channel image, all channels are processed separately.
  • hist – Destination histogram with one row, histSize columns, and the CV_32S type.
  • histSize – Size of the histogram.
  • lowerLevel – Lower boundary of lowest-level bin.
  • upperLevel – Upper boundary of highest-level bin.

gpu::histRange

C++: void gpu::histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels)
C++: void gpu::histRange(const GpuMat& src, GpuMat* hist, const GpuMat* levels)

Calculates a histogram with bins determined by the levels array.

Parameters:
  • src – Source image. CV_8U, CV_16U, or CV_16S depth and 1 or 4 channels are supported. For a four-channel image, all channels are processed separately.
  • hist – Destination histogram with one row, (levels.cols-1) columns, and the CV_32SC1 type.
  • levels – Number of levels in the histogram.