@ -3,8 +3,6 @@ Camera Calibration and 3d Reconstruction
..highlight:: cpp
..index:: gpu::StereoBM_GPU
gpu::StereoBM_GPU
@ -40,19 +38,18 @@ The class for computing stereo correspondence using block matching algorithm. ::
...
};
This class computes the disparity map using block matching algorithm. The class also performs pre- and post- filtering steps: sobel prefiltering (if ``PREFILTER_XSOBEL`` flag is set) and low textureness filtering (if ``averageTexThreshols``:math:`>` 0). If ``avergeTexThreshold = 0`` low textureness filtering is disabled, otherwise disparity is set to 0 in each point ``(x, y)`` where for left image
This class computes the disparity map using block matching algorithm. The class also performs pre- and post- filtering steps: sobel prefiltering (if ``PREFILTER_XSOBEL`` flag is set) and low textureness filtering (if ``averageTexThreshols > 0``). If ``avergeTexThreshold = 0``, low textureness filtering is disabled, otherwise the disparity is set to 0 in each point ``(x, y)``, where for the left image
..math::
\sum HorizontalGradiensInWindow(x, y, winSize) < (winSize \cdot winSize) \cdot avergeTexThreshold
\sum HorizontalGradiensInWindow(x, y, winSize) < (winSize \cdot winSize) \cdot avergeTexThreshold
Some heuristics that tries to estmate if the current GPU will be faster then CPU in this algorithm. It queries current active device.
..index:: gpu::StereoBeliefPropagation
gpu::StereoBeliefPropagation
@ -152,11 +145,11 @@ The class for computing stereo correspondence using belief propagation algorithm
The class implements Pedro F. Felzenszwalb algorithm [Pedro F. Felzenszwalb and Daniel P. Huttenlocher. Efficient belief propagation for early vision. International Journal of Computer Vision, 70(1), October 2006]. It can compute own data cost (using truncated linear model) or use user-provided data cost.
**Please note:**``StereoBeliefPropagation`` requires a lot of memory:
**Note:**``StereoBeliefPropagation`` requires a lot of memory:
For more details please see [Pedro F. Felzenszwalb and Daniel P. Huttenlocher. Efficient belief propagation for early vision. International Journal of Computer Vision, 70(1), October 2006].
By default :cpp:class:`StereoBeliefPropagation` uses floating-point arithmetics and ``CV_32FC1`` type for messages. But also it can use fixed-point arithmetics and ``CV_16SC1`` type for messages for better perfomance. To avoid overflow in this case, the parameters must satisfy
By default,:cpp:class:`StereoBeliefPropagation` uses floating-point arithmetics and ``CV_32FC1`` type for messages. But also it can use fixed-point arithmetics and ``CV_16SC1`` type for messages for better performance. To avoid overflow in this case, the parameters must satisfy
Some heuristics that tries to compute recommended parameters (``ndisp``, ``iters`` and ``levels``) for specified image size (``width`` and ``height``).
:param data:The user specified data cost. It must have ``msg_type`` type and :math:`\texttt{imgRows} \cdot \texttt{ndisp} \times \texttt{imgCols}` size.
:param data:The user specified data cost, a matrix of ``msg_type`` type and ``Size(<image columns>*ndisp, <image rows>)`` size.
:param disparity:Output disparity map. If ``disparity`` is empty output type will be ``CV_16SC1``, otherwise output type will be ``disparity.type()``.
:param disparity:Output disparity map. If the matrix is empty, it will be created as ``CV_16SC1`` matrix, otherwise the type will be retained.
:param stream:Stream for the asynchronous version.
..index:: gpu::StereoConstantSpaceBP
gpu::StereoConstantSpaceBP
@ -314,17 +299,15 @@ The class for computing stereo correspondence using constant space belief propag
The class implements Q. Yang algorithm [Q. Yang, L. Wang, and N. Ahuja. A constant-space belief propagation algorithm for stereo matching. In CVPR, 2010]. ``StereoConstantSpaceBP`` supports both local minimum and global minimum data cost initialization algortihms. For more details please see the paper. By default local algorithm is used, and to enable global algorithm set ``use_local_init_data_cost`` to false.
..cpp:function:: gpu::StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP, int iters = DEFAULT_ITERS, int levels = DEFAULT_LEVELS, int nr_plane = DEFAULT_NR_PLANE, int msg_type = CV_32F)
..cpp:function::gpu::StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane, float max_data_term, float data_weight, float max_disc_term, float disc_single_jump, int min_disp_th = 0, int msg_type = CV_32F)
..cpp:function:: StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane, float max_data_term, float data_weight, float max_disc_term, float disc_single_jump, int min_disp_th = 0, int msg_type = CV_32F)
For more details please see [Q. Yang, L. Wang, and N. Ahuja. A constant-space belief propagation algorithm for stereo matching. In CVPR, 2010].
For more details please see
qx_csbp
.
By default :cpp:class:`StereoConstantSpaceBP` uses floating-point arithmetics and ``CV_32FC1`` type for messages. But also it can use fixed-point arithmetics and ``CV_16SC1`` type for messages for better perfomance. To avoid overflow in this case, the parameters must satisfy
By default ``StereoConstantSpaceBP`` uses floating-point arithmetics and ``CV_32FC1`` type for messages. But also it can use fixed-point arithmetics and ``CV_16SC1`` type for messages for better perfomance. To avoid overflow in this case, the parameters must satisfy
..cpp:function:: void gpu::StereoConstantSpaceBP::estimateRecommendedParams( int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane)
Some heuristics that tries to compute parameters (``ndisp``, ``iters``, ``levels`` and ``nr_plane``) for specified image size (``width`` and ``height``).
Some heuristics that tries to compute parameters (ndisp, iters, levelsand nrplane) for specified image size (widthand height).
The stereo correspondence operator. Finds the disparity for the specified rectified stereo pair.
:param left:Left image; supports ``CV_8UC1``, ``CV_8UC3`` and ``CV_8UC4`` types.
:param left:Left image; supports ``CV_8UC1``, ``CV_8UC3`` and ``CV_8UC4`` types.
:param right:Right image with the same size and the same type as the left one.
:param disparity:Output disparity map. If ``disparity`` is empty output type will be ``CV_16SC1``, otherwise output type will be ``disparity.type()``.
:param disparity:Output disparity map. If ``disparity`` is empty output type will be ``CV_16SC1``, otherwise output type will be ``disparity.type()``.
:param stream:Stream for the asynchronous version.
..index:: gpu::DisparityBilateralFilter
.._gpu::DisparityBilateralFilter:
gpu::DisparityBilateralFilter
-----------------------------
..cpp:class:: gpu::DisparityBilateralFilter
The class for disparity map refinement using joint bilateral filtering. ::
class DisparityBilateralFilter
class CV_EXPORTS DisparityBilateralFilter
{
public:
enum { DEFAULT_NDISP = 64 };
@ -429,15 +411,13 @@ The class for disparity map refinement using joint bilateral filtering. ::
The class implements Q. Yang algorithm [Q. Yang, L. Wang, and N. Ahuja. A constant-space belief propagation algorithm for stereo matching. In CVPR, 2010].
Refines disparity map using joint bilateral filtering.
:param disparity:Input disparity map; supports ``CV_8UC1`` and ``CV_16SC1`` types.
:param disparity:Input disparity map; supports ``CV_8UC1`` and ``CV_16SC1`` types.
:param image:Input image; supports ``CV_8UC1`` and ``CV_8UC3`` types.
:param image:Input image; supports ``CV_8UC1`` and ``CV_8UC3`` types.
:param dst:Destination disparity map; will have the same size and type as ``disparity``.
:param dst:Destination disparity map; will have the same size and type as ``disparity``.
:param stream:Stream for the asynchronous version.
..index:: gpu::drawColorDisp
gpu::drawColorDisp
@ -485,17 +461,15 @@ gpu::drawColorDisp
Does coloring of disparity image.
:param src_disp:Source disparity image. Supports ``CV_8UC1`` and ``CV_16SC1`` types.
:param src_disp:Source disparity image. Supports ``CV_8UC1`` and ``CV_16SC1`` types.
:param dst_disp:Output disparity image. Will have the same size as ``src_disp`` and ``CV_8UC4`` type in ``BGRA`` format (alpha = 255).
:param dst_disp:Output disparity image. Will have the same size as ``src_disp`` and ``CV_8UC4`` type in ``BGRA`` format (alpha = 255).
:param ndisp:Number of disparities.
:param stream:Stream for the asynchronous version.
This function converts :math:`[0..ndisp)` interval to :math:`[0..240, 1, 1]` in ``HSV`` color space, than convert ``HSV`` color space to ``RGB``.
This function draws a colorized disparity map by converting disparity values from ``[0..ndisp)`` interval first to ``HSV`` color space (where different disparity values correspond to different hues) and then converting the pixels to ``RGB`` for visualization.
..index:: gpu::reprojectImageTo3D
@ -507,17 +481,15 @@ gpu::reprojectImageTo3D
Reprojects disparity image to 3D space.
:param disp:Input disparity image; supports ``CV_8U`` and ``CV_16S`` types.
:param disp:Input disparity image; supports ``CV_8U`` and ``CV_16S`` types.
:param xyzw:Output 4-channel floating-point image of the same size as ``disp``. Each element of ``xyzw(x,y)`` will contain the 3D coordinates ``(x,y,z,1)`` of the point ``(x,y)``, computed from the disparity map.
:param xyzw:Output 4-channel floating-point image of the same size as ``disp``. Each element of ``xyzw(x,y)`` will contain the 3D coordinates ``(x,y,z,1)`` of the point ``(x,y)``, computed from the disparity map.
:param Q::math:`4 \times 4` perspective transformation matrix that can be obtained via :c:func:`stereoRectify`.
:param Q::math:`4 \times 4` perspective transformation matrix that can be obtained via :ref:`StereoRectify` .
:param stream:Stream for the asynchronous version.
This is a simple lightweight class that encapsulate pitched memory on GPU. It is intended to pass to nvcc-compiled code, i.e. CUDA kernels. So it is used internally by OpenCV and by users writes own device code. Its members can be called both from host and from device code. ::
This lightweight class encapsulates pitched memory on a GPU and is passed to nvcc-compiled code (CUDA kernels). Typically, it is used internally by OpenCV and by users who write device code. You can call its members from both host and device code.
::
template <typename T> struct DevMem2D_
{
@ -31,7 +28,7 @@ This is a simple lightweight class that encapsulate pitched memory on GPU. It is
__CV_GPU_HOST_DEVICE__ size_t elemSize() const;
/* returns pointer to the beggining of given image row */
/* returns pointer to the beggining of the given image row */
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0);
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const;
};
@ -41,29 +38,30 @@ This is a simple lightweight class that encapsulate pitched memory on GPU. It is
typedef DevMem2D_<int> DevMem2Di;
..index:: gpu::PtrStep_
..index:: gpu::PtrStep\_
gpu::PtrStep\_
--------------
..cpp:class:: gpu::PtrStep_
..cpp:class:: gpu::PtrStep\_
This is structure is similar to :cpp:class:`gpu::DevMem2D_` but contains only pointer and row step. Width and height fields are excluded due to performance reasons. The structure is for internal use or for users who write own device code. ::
This structure is similar to
:cpp:class:`DevMem2D_` but contains only a pointer and row step. Width and height fields are excluded due to performance reasons. The structure is intended for internal use or for users who write device code.
::
template<typename T> struct PtrStep_
{
T* data;
size_t step;
T* data;
size_t step;
PtrStep_();
PtrStep_(const DevMem2D_<T>& mem);
PtrStep_();
PtrStep_(const DevMem2D_<T>& mem);
typedef T elem_type;
enum { elem_size = sizeof(elem_type) };
typedef T elem_type;
enum { elem_size = sizeof(elem_type) };
__CV_GPU_HOST_DEVICE__ size_t elemSize() const;
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0);
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const;
__CV_GPU_HOST_DEVICE__ size_t elemSize() const;
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0);
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const;
};
typedef PtrStep_<unsigned char> PtrStep;
@ -71,27 +69,23 @@ This is structure is similar to :cpp:class:`gpu::DevMem2D_` but contains only po
typedef PtrStep_<int> PtrStepi;
..index:: gpu::PtrElemStrp\_
..index:: gpu::PtrElemStep_
gpu::PtrElemStep\_
gpu::PtrElemStrp\_
------------------
..cpp:class:: gpu::PtrElemStep_
..cpp:class:: gpu::PtrElemStrp\_
This is structure is similar to :cpp:class:`gpu::DevMem2D_` but contains only pointer and row step in elements. Width and height fields are excluded due to performance reasons. This class is can only be constructed if ``sizeof(T)`` is a multiple of 256. The structure is for internal use or for users who write own device code. ::
This structure is similar to
:cpp:class:`DevMem2D_` but contains only pointer and row step in elements. Width and height fields are excluded due to performance reasons. This class can only be constructed if ``sizeof(T)`` is a multiple of 256. The structure is intended for internal use or for users who write device code.
::
template<typename T> struct PtrElemStep_ : public PtrStep_<T>
{
PtrElemStep_(const DevMem2D_<T>& mem);
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0);
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const;
PtrElemStep_(const DevMem2D_<T>& mem);
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0);
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const;
};
typedef PtrElemStep_<unsigned char> PtrElemStep;
typedef PtrElemStep_<float> PtrElemStepf;
typedef PtrElemStep_<int> PtrElemStepi;
..index:: gpu::GpuMat
@ -99,47 +93,58 @@ gpu::GpuMat
-----------
..cpp:class:: gpu::GpuMat
The base storage class for GPU memory with reference counting. Its interface is almost :c:type:`Mat` interface with some limitations, so using it won't be a problem. The limitations are no arbitrary dimensions support (only 2D), no functions that returns references to its data (because references on GPU are not valid for CPU), no expression templates technique support. Because of last limitation please take care with overloaded matrix operators - they cause memory allocations. The ``GpuMat`` class is convertible to :cpp:class:`gpu::DevMem2D_` and :cpp:class:`gpu::PtrStep_` so it can be passed to directly to kernel.
This is a base storage class for GPU memory with reference counting. Its interface matches the
:c:type:`Mat` interface with the following limitations:
*
no arbitrary dimensions support (only 2D)
*
no functions that return references to their data (because references on GPU are not valid for CPU)
*
no expression templates technique support
Beware that the latter limitation may lead to overloaded matrix operators that cause memory allocations. The ``GpuMat`` class is convertible to :cpp:class:`gpu::DevMem2D_` and :cpp:class:`gpu::PtrStep_` so it can be passed to directly to kernel.
**Please note:** In contrast with :c:type:`Mat`, in most cases ``GpuMat::isContinuous() == false`` , i.e. rows are aligned to size depending on hardware. Also single row ``GpuMat`` is always a continuous matrix. ::
**Note:**
In contrast with :c:type:`Mat`, in most cases ``GpuMat::isContinuous() == false`` . This means that rows are aligned to size depending on the hardware. Single-row ``GpuMat`` is always a continuous matrix. ::
class GpuMat
class CV_EXPORTS GpuMat
{
public:
//! default constructor
GpuMat();
//! default constructor
GpuMat();
GpuMat(int rows, int cols, int type);
GpuMat(Size size, int type);
GpuMat(int rows, int cols, int type);
GpuMat(Size size, int type);
.....
.....
//! builds GpuMat from Mat. Perfom blocking upload to device.
explicit GpuMat (const Mat& m);
//! builds GpuMat from Mat. Blocks uploading to device.
explicit GpuMat (const Mat& m);
//! returns lightweight DevMem2D_ structure for passing
//to nvcc-compiled code. Contains size, data ptr and step.
template <class T> operator DevMem2D_<T>() const;
template <class T> operator PtrStep_<T>() const;
//! returns lightweight DevMem2D_ structure for passing
//to nvcc-compiled code. Contains size, data ptr and step.
template <class T> operator DevMem2D_<T>() const;
template <class T> operator PtrStep_<T>() const;
//! pefroms blocking upload data to GpuMat.
void upload(const cv::Mat& m);
void upload(const CudaMem& m, Stream& stream);
//! blocks uploading data to GpuMat.
void upload(const cv::Mat& m);
void upload(const CudaMem& m, Stream& stream);
//! downloads data from device to host memory. Blocking calls.
operator Mat() const;
void download(cv::Mat& m) const;
//! downloads data from device to host memory. Blocking calls.
operator Mat() const;
void download(cv::Mat& m) const;
//! download async
void download(CudaMem& m, Stream& stream) const;
//! download async
void download(CudaMem& m, Stream& stream) const;
};
**Please note:** Is it a bad practice to leave static or global ``GpuMat`` variables allocated, i.e. to rely on its destructor. That is because destruction order of such variables and CUDA context is undefined and GPU memory release function returns error if CUDA context has been destroyed before.
See also: :c:type:`Mat`.
**Note:**
You are not recommended to leave static or global ``GpuMat`` variables allocated, that is to rely on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory release function returns error if the CUDA context has been destroyed before.
See Also:
:func:`Mat`
..index:: gpu::CudaMem
@ -147,47 +152,50 @@ gpu::CudaMem
------------
..cpp:class:: gpu::CudaMem
This is a class with reference counting that wraps special memory type allocation functions from CUDA. Its interface is also :c:type:`Mat`-like but with additional memory type parameter:
* ``ALLOC_PAGE_LOCKED`` Set page locked memory type, used commonly for fast and asynchronous upload/download data from/to GPU.
* ``ALLOC_ZEROCOPY`` Specifies zero copy memory allocation, i.e. with possibility to map host memory to GPU address space if supported.
* ``ALLOC_WRITE_COMBINED`` Sets write combined buffer which is not cached by CPU. Such buffers are used to supply GPU with data when GPU only reads it. The advantage is better CPU cache utilization.
**Please note:** Allocation size of such memory types is usually limited. For more details please see "CUDA 2.2 Pinned Memory APIs" document or "CUDA_C Programming Guide". ::
class CudaMem
This class with reference counting wraps special memory type allocation functions from CUDA. Its interface is also
:func:`Mat`-like but with additional memory type parameters.
*
``ALLOC_PAGE_LOCKED``: Sets a page locked memory type, used commonly for fast and asynchronous upload/download data from/to GPU.
*
``ALLOC_ZEROCOPY``: Specifies a zero copy memory allocation that enables mapping the host memory to GPU address space, if supported.
*
``ALLOC_WRITE_COMBINED``: Sets the write combined buffer that is not cached by CPU. Such buffers are used to supply GPU with data when GPU only reads it. The advantage is a better CPU cache utilization.
**Note:**
Allocation size of such memory types is usually limited. For more details please see "CUDA 2.2 Pinned Memory APIs" document or "CUDA_C Programming Guide".
::
class CV_EXPORTS CudaMem
{
public:
enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2,
ALLOC_WRITE_COMBINED = 4 };
enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2,
ALLOC_WRITE_COMBINED = 4 };
CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
//! creates from cv::Mat with coping data
explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
//! creates from cv::Mat with coping data
explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
......
......
void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
//! returns matrix header with disabled ref. counting for CudaMem data.
Mat createMatHeader() const;
operator Mat() const;
//! returns matrix header with disabled ref. counting for CudaMem data.
Mat createMatHeader() const;
operator Mat() const;
//! maps host memory into device address space
GpuMat createGpuMatHeader() const;
operator GpuMat() const;
//! maps host memory into device address space
GpuMat createGpuMatHeader() const;
operator GpuMat() const;
//if host memory can be mapperd to gpu address space;
static bool canMapHostMemory();
//if host memory can be mapped to gpu address space;
static bool canMapHostMemory();
int alloc_type;
int alloc_type;
};
..index:: gpu::CudaMem::createMatHeader
gpu::CudaMem::createMatHeader
@ -195,11 +203,7 @@ gpu::CudaMem::createMatHeader
..cpp:function:: Mat gpu::CudaMem::createMatHeader() const
Maps CPU memory to GPU address space and creates :cpp:class:`gpu::GpuMat` header without reference counting for it. This can be done only if memory was allocated with ``ALLOC_ZEROCOPY`` flag and if it is supported by hardware (laptops often share video and CPU memory, so address spaces can be mapped, and that eliminates extra copy).
Maps CPU memory to GPU address space and creates :cpp:class:`gpu::GpuMat` header without reference counting for it. This can be done only if memory was allocated with ``ALLOC_ZEROCOPY`` flag and if it is supported by the hardware (laptops often share video and CPU memory, so address spaces can be mapped, and that eliminates an extra copy).
Returns true if the current hardware supports address space mapping and ``ALLOC_ZEROCOPY`` memory allocation.
..index:: gpu::Stream
gpu::Stream
-----------
..cpp:class:: gpu::Stream
This class encapsulated queue of the asynchronous calls. Some functions have overloads with additional ``gpu::Stream`` parameter. The overloads do initialization work (allocate output buffers, upload constants, etc.), start GPU kernel and return before results are ready. A check if all operation are complete can be performed via :cpp:func:`gpu::Stream::queryIfComplete`. Asynchronous upload/download have to be performed from/to page-locked buffers, i.e. using :cpp:class:`gpu::CudaMem` or :c:type:`Mat` header that points to a region of :cpp:class:`gpu::CudaMem`.
This class encapsulated a queue of asynchronous calls. Some functions have overloads with the additional ``gpu::Stream`` parameter. The overloads do initialization work (allocate output buffers, upload constants, and so on), start the GPU kernel, and return before results are ready. You can check whether all operation are complete via :cpp:func:`gpu::Stream::queryIfComplete`. You can asynchronously upload/download data from/to page-locked buffers, using :cpp:class:`gpu::CudaMem` or :c:type:`Mat` header that points to a region of :cpp:class:`gpu::CudaMem`.
**Please note the limitation**: currently it is not guaranteed that all will work properly if one operation will be enqueued twice with different data. Some functions use constant GPU memory and next call may update the memory before previous has been finished. But calling asynchronously different operations is safe because each operation has own constant buffer. Memory copy/upload/download/set operations to buffers hold by user are also safe. ::
**Note:**
Currently, you may face problems if an operation is enqueued twice with different data. Some functions use the constant GPU memory, and next call may update the memory before the previous one has been finished. But calling different operations asynchronously is safe because each operation has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are also safe.
::
class Stream
class CV_EXPORTS Stream
{
public:
Stream();
~Stream();
Stream();
~Stream();
Stream(const Stream&);
Stream& operator=(const Stream&);
Stream(const Stream&);
Stream& operator=(const Stream&);
bool queryIfComplete();
void waitForCompletion();
bool queryIfComplete();
void waitForCompletion();
//! downloads asynchronously.
// Warning! cv::Mat must point to page locked memory
Blocks until all operations in the stream are complete.
..index:: gpu::StreamAccessor
gpu::StreamAccessor
-------------------
..cpp:class:: gpu::StreamAccessor
This class provides possibility to get ``cudaStream_t`` from :cpp:class:`gpu::Stream`. This class is declared in ``stream_accessor.hpp`` because that is only public header that depend on Cuda Runtime API. Including it will bring the dependency to your code. ::
This class enables getting ``cudaStream_t`` from :cpp:class:`gpu::Stream` and is declared in ``stream_accessor.hpp`` because it is the only public header that depends on the CUDA Runtime API. Including it brings a dependency to your code.
..cpp:function:: void gpu::createContinuous(int rows, int cols, int type, GpuMat& m)
Creates continuous matrix in GPU memory.
Creates a continuous matrix in the GPU memory.
:param rows:Row count.
@ -319,19 +314,18 @@ gpu::createContinuous
:param type:Type of the matrix.
:param m:Destination matrix. Will be only reshaped if it has proper type and area (``rows`` :math:`\times` ``cols``).
Also the following wrappers are available:
..cpp:function:: GpuMat gpu::createContinuous(int rows, int cols, int type)
..cpp:function:: void gpu::createContinuous(Size size, int type, GpuMat& m)
..cpp:function:: GpuMat gpu::createContinuous(Size size, int type)
Matrix is called continuous if its elements are stored continuously, i.e. wuthout gaps in the end of each row.
:param m:Destination matrix. This parameter changes only if it has a proper type and area (``rows x cols``).
The following wrappers are also available:
*
..cpp:function:: GpuMat gpu::createContinuous(int rows, int cols, int type)
*
..cpp:function:: void gpu::createContinuous(Size size, int type, GpuMat& m)
*
..cpp:function:: GpuMat gpu::createContinuous(Size size, int type)
Matrix is called continuous if its elements are stored continuously, that is wuthout gaps in the end of each row.
..index:: gpu::ensureSizeIsEnough
@ -339,16 +333,21 @@ gpu::ensureSizeIsEnough
---------------------------
..cpp:function:: void gpu::ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m)
Ensures that size of matrix is big enough and matrix has proper type. The function doesn't reallocate memory if the matrix has proper attributes already.
..cpp:function:: void gpu::ensureSizeIsEnough(Size size, int type, GpuMat& m)
Ensures that the size of a matrix is big enough and the matrix has a proper type. The function does not reallocate memory if the matrix has proper attributes already.
:param rows:Minimum desired number of rows.
:param cols:Minimum desired number of cols.
:param cols:Minimum desired number of columns.
:param size:rows and cols passed as a structure
:param type:Desired matrix type.
:param m:Destination matrix.
Also the following wrapper is available:
The following wrapper is also available:
..cpp:function:: void gpu::ensureSizeIsEnough(Size size, int type, GpuMat& m)
Performs mean-shift filtering for each point of the source image. It maps each point of the source image into another point, and as the result we have new color and new position of each point.
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, we have a new color and new position of each point.
:param src:Source image. Only ``CV_8UC4`` images are supported for now.
:param src:Source image. Only ``CV_8UC4`` images are supported for now.
:param dst:Destination image, containing color of mapped points. Will have the same size and type as ``src``.
:param dst:Destination image containing the color of mapped points. The size and type is the same as ``src`` .
:param sp:Spatial window radius.
@ -23,21 +24,21 @@ gpu::meanShiftFiltering
:param criteria:Termination criteria. See :c:type:`TermCriteria`.
Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix. Can handle real matrices ``CV32FC1`` and complex matrices in the interleaved format ``CV32FC2``.
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).
:param src:Source matrix (real or complex).
@ -235,55 +229,62 @@ gpu::dft
* **DFT_ROWS** Transform each individual row of the source matrix.
* **DFT_SCALE** Scale the result: divide it by the number of elements in the transform (it's obtained from ``dft_size``).
* **DFT_INVERSE** Inverse DFT must be perfromed for complex-complex case (real-complex and complex-real cases are respectively forward and inverse always).
* **DFT_SCALE** Scale the result: divide it by the number of elements in the transform (obtained from ``dft_size`` ).
* **DFT_REAL_OUTPUT** The source matrix is the result of real-complex transform, so the destination matrix must be real.
* **DFT_INVERSE** Invert DFT. Use for complex-complex cases (real-complex and complex-real cases are respectively forward and inverse always).
The source matrix should be continuous, otherwise reallocation and data copying will be performed. Function chooses the operation mode depending on the flags, size and channel count of the source matrix:
* If the source matrix is complex and the output isn't specified as real then the destination matrix will be complex, will have ``dft_size`` size and ``CV_32FC2`` type. It will contain full result of the DFT (forward or inverse).
* **DFT_REAL_OUTPUT** Specify the output as real. The source matrix is the result of real-complex transform, so the destination matrix must be real.
* If the source matrix is complex and the output is specified as real then function assumes that its input is the result of the forward transform (see next item). The destionation matrix will have ``dft_size`` size and ``CV_32FC1`` type. It will contain result of the inverse DFT.
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 real (i.e. its type is ``CV_32FC1``) then forward DFT will be performed. The result of the DFT will be packed into complex (``CV_32FC2``) matrix so its width will be ``dft_size.width / 2 + 1``, but if the source is a single column then height will be reduced instead of width.
*
If the source matrix is complex and the output is not specified as real, the destination matrix is complex, has the ``dft_size`` size and ``CV_32FC2`` type. The destination matrix contains a full result of the DFT (forward or inverse).
See also: :c:func:`dft`.
*
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 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.
Computes a proximity map for a raster template and an image where the template is searched for.
:param image:Source image. ``CV_32F`` and ``CV_8U`` depth images (1..4 channels) are supported for now.
:param templ:Template image. Must have the same size and type as ``image``.
:param image:Source image. ``CV_32F`` and ``CV_8U`` depth images (1..4 channels) are supported for now.
:param result:Map containing comparison results (``CV_32FC1``). If ``image`` is ``W`` :math:`\times` ``H`` and ``templ`` is ``w`` :math:`\times` ``h`` then ``result`` must be ``(W-w+1)`` :math:`\times` ``(H-h+1)``.
:param templ:Template image. The size and type is the same as ``image`` .
:param method:Specifies the way which the template must be compared with the image.
:param 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*.
Following methods are supported for the ``CV_8U`` depth images for now:
:param method:Specifies the way to compare the template with the image.
* 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_8U`` depth images for now:
Following methods are supported for the ``CV_32F`` images for now:
* CV_TM_SQDIFF
* CV_TM_SQDIFF_NORMED
* CV_TM_CCORR
* CV_TM_CCORR_NORMED
* CV_TM_CCOEFF
* CV_TM_CCOEFF_NORMED
* CV_TM_SQDIFF
* CV_TM_CCORR
See also: :c:func:`matchTemplate`.
The following methods are supported for the ``CV_32F`` images for now:
Values of pixels with non-integer coordinates are computed using bilinear interpolation.
See Also: :c:func:`remap` .
..index:: gpu::cvtColor
@ -378,25 +376,24 @@ gpu::cvtColor
-----------------
..cpp:function:: void gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0)
..cpp:function:: void gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream)
..cpp:function:: void gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream)
Converts image from one color space to another.
:param src:Source image with ``CV_8U``, ``CV_16U`` or ``CV_32F`` depth and 1, 3 or 4 channels.
:param src:Source image with ``CV_8U``, ``CV_16U``, or ``CV_32F`` depth and 1, 3, or 4 channels.
:param dst:Destination image; will have the same size and the same depth as ``src``.
:param dst:Destination image. The size and depth is the same as ``src`` .
:param code:Color space conversion code. For details see :c:func:`cvtColor`. Conversion to/from Luv and Bayer color spaces doesn't supported.
:param code:Color space conversion code. For details, see :func:`cvtColor` . Conversion to/from Luv and Bayer color spaces is not supported.
:param dcn:Number of channels in the destination image; if the parameter is 0, the number of the channels will be derived automatically from ``src`` and the ``code``.
:param 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`` .
:param stream:Stream for the asynchronous version.
3-channel color spaces (like ``HSV``, ``XYZ``, etc) can be stored to 4-channel image for better perfomance.
See also: :c:func:`cvtColor`.
3-channel color spaces (like ``HSV``,``XYZ``, and so on) can be stored to a 4-channel image for better perfomance.
See Also:
:func:`cvtColor` .
..index:: gpu::threshold
@ -408,21 +405,20 @@ gpu::threshold
Applies a fixed-level threshold to each array element.
:param src:Source array (single-channel). ``CV_64F`` depth is not supported.
:param dst:Destination array; will have the same size and the same type as ``src``.
:param dst:Destination array. The size and type is the same as ``src`` .
:param thresh:Threshold value.
:param maxVal:Maximum value to use with ``THRESH_BINARY`` and ``THRESH_BINARY_INV`` thresholding types.
:param maxVal:Maximum value to use with ``THRESH_BINARY`` and ``THRESH_BINARY_INV`` threshold types.
:param thresholdType:Thresholding type. For details see :c:func:`threshold`. ``THRESH_OTSU`` thresholding type doesn't supported.
:param thresholdType:Threshold type. For details, see :func:`threshold` . The ``THRESH_OTSU`` threshold type is not supported.
:param stream:Stream for the asynchronous version.
See also: :c:func:`threshold`.
See Also:
:func:`threshold` .
..index:: gpu::resize
@ -432,35 +428,32 @@ gpu::resize
Resizes an image.
:param src:Source image. Supports ``CV_8UC1`` and ``CV_8UC4`` types.
:param src:Source image. Supports the ``CV_8UC1`` and ``CV_8UC4`` types.
:param dst:Destination image. It will have size ``dsize`` (when it is non-zero) or the size computed from ``src.size()`` and ``fx`` and ``fy``. The type of ``dst`` will be the same as of ``src``.
:param dst:Destination image. The size is ``dsize`` (when it is non-zero) or the size is computed from ``src.size()``, ``fx``, and ``fy`` . The type is the same as ``src`` .
:param dsize:Destination image size. If it is zero, then it is computed as:
:param dsize:Destination image size. If it is zero, it is computed as:
:param flags:Combination of interpolation methods, see :c:func:`resize`, and the optional flag ``WARP_INVERSE_MAP`` that means that ``M`` is the inverse transformation(:math:`dst \rightarrow src` ). Supports only ``INTER_NEAREST``, ``INTER_LINEAR`` and ``INTER_CUBIC`` interpolation methods.
See also: :c:func:`warpAffine`.
:param flags:Combination of interpolation methods (see :func:`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.
See Also:
:func:`warpAffine` .
..index:: gpu::warpPerspective
@ -492,19 +484,18 @@ gpu::warpPerspective
Applies a perspective transformation to an image.
:param src:Source image. Supports ``CV_8U``, ``CV_16U``, ``CV_32S`` or ``CV_32F`` depth and 1, 3 or 4 channels.
:param src:Source image. Supports ``CV_8U``, ``CV_16U``, ``CV_32S``, or ``CV_32F`` depth and 1, 3, or 4 channels.
:param dst:Destination image; will have size ``dsize`` and the same type as ``src``.
:param dst:Destination image. The size is ``dsize`` . The type is the same as ``src`` .
:param flags:Combination of interpolation methods, see :c:func:`resize`, and the optional flag ``WARP_INVERSE_MAP`` that means that ``M`` is the inverse transformation (:math:`dst \rightarrow src` ). Supports only ``INTER_NEAREST``, ``INTER_LINEAR`` and ``INTER_CUBIC`` interpolation methods.
See also: :c:func:`warpPerspective`.
:param flags:Combination of interpolation methods (see :func:`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.
See Also:
:func:`warpPerspective` .
..index:: gpu::rotate
@ -514,23 +505,22 @@ gpu::rotate
Rotates an image around the origin (0,0) and then shifts it.
:param src:Source image. Supports ``CV_8UC1`` and ``CV_8UC4`` types.
:param src:Source image. Supports ``CV_8UC1`` and ``CV_8UC4`` types.
:param dst:Destination image; will have size ``dsize`` and the same type as ``src``.
:param dst:Destination image. The size is ``dsize`` . The type is the same as ``src`` .
:param dsize:Size of the destination image.
:param angle:Angle of rotation in degrees.
:param xShift:Shift along horizontal axis.
:param yShift:Shift along vertical axis.
:param xShift:Shift along the horizontal axis.
:param interpolation:Interpolation method. Supports only ``INTER_NEAREST``, ``INTER_LINEAR`` and ``INTER_CUBIC``.
See also: :cpp:func:`gpu::warpAffine`.
:param yShift:Shift along the vertical axis.
:param interpolation:Interpolation method. Only ``INTER_NEAREST``, ``INTER_LINEAR``, and ``INTER_CUBIC`` are supported.
See Also:
:func:`gpu::warpAffine` .
..index:: gpu::copyMakeBorder
@ -538,38 +528,34 @@ gpu::copyMakeBorder
-----------------------
..cpp:function:: void gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, const Scalar& value = Scalar())
Copies 2D array to a larger destination array and pads borders with the given constant.
Copies a 2D array to a larger destination array and pads borders with the given constant.
:param src:Source image. Supports ``CV_8UC1``, ``CV_8UC4``, ``CV_32SC1`` and ``CV_32FC1`` types.
:param src:Source image. ``CV_8UC1``, ``CV_8UC4``, ``CV_32SC1``, and ``CV_32FC1`` types are supported.
:param dst:The destination image; will have the same type as ``src`` and the size ``Size(src.cols+left+right, src.rows+top+bottom)``.
:param dst:Destination image. The type is the same as ``src`` . The size is ``Size(src.cols+left+right, src.rows+top+bottom)``.
:param top, bottom, left, right:Specify how much pixels in each direction from the source image rectangle one needs to extrapolate, e.g. ``top=1, bottom=1, left=1, right=1`` mean that 1 pixel-wide border needs to be built.
:param 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.
:param src:Source image. Supports only ``CV_32SC1`` type.
:param src:Source image. Only the ``CV_32SC1`` type is supported.
:param sqr:Squared source image. Supports only ``CV_32FC1`` type.
:param sqr:Squared source image. Only the ``CV_32FC1`` type is supported.
:param dst:Destination image; will have the same type and the same size as ``src``.
:param dst:Destination image. The type and size is the same as ``src`` .
:param rect:Rectangular window.
..index:: gpu::evenLevels
gpu::evenLevels
@ -578,16 +564,14 @@ gpu::evenLevels
Computes levels with even distribution.
:param levels:Destination array. ``levels`` will have 1 row and ``nLevels`` cols and ``CV_32SC1`` type.
:param levels:Destination array. ``levels`` has 1 row, ``nLevels`` columns, and the ``CV_32SC1`` type.
:param nLevels:Number of levels being computed. ``nLevels`` must be at least 2.
:param nLevels:Number of computed levels. ``nLevels`` must be at least 2.
:param lowerLevel:Lower boundary value of the lowest level.
:param upperLevel:Upper boundary value of the greatest level.
..index:: gpu::histEven
gpu::histEven
@ -596,19 +580,17 @@ gpu::histEven
..cpp:function:: void gpu::histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4])
Calculates histogram with evenly distributed bins.
Calculates a histogram with evenly distributed bins.
:param src:Source image. Supports ``CV_8U``, ``CV_16U`` or ``CV_16S`` depth and 1 or 4 channels. For four-channel image all channels are processed separately.
:param 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.
:param hist:Destination histogram. Will have one row, ``histSize`` cols and ``CV_32S`` type.
:param hist:Destination histogram with one row, ``histSize`` columns, and the ``CV_32S`` type.
:param histSize:Size of histogram.
:param lowerLevel:Lower boundary of lowest level bin.
:param upperLevel:Upper boundary of highest level bin.
:param histSize:Size of the histogram.
:param lowerLevel:Lower boundary of lowest-level bin.
:param upperLevel:Upper boundary of highest-level bin.
Calculates a histogram with bins determined by the `levels` array.
Calculates histogram with bins determined by levels array.
:param 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.
:param src:Source image. Supports ``CV_8U``, ``CV_16U`` or ``CV_16S`` depth and 1 or 4 channels. For four-channel image all channels are processed separately.
:param hist:Destination histogram with one row, ``(levels.cols-1)`` columns, and the ``CV_32SC1`` type.
:param hist:Destination histogram. Will have one row, ``(levels.cols-1)`` cols and ``CV_32SC1`` type.
..cpp:function:: int gpu::getCudaEnabledDeviceCount()
Returns number of CUDA-enabled devices installed. It is to be used before any other GPU functions calls. If OpenCV is compiled without GPU support this function returns 0.
..cpp:function:: int getCudaEnabledDeviceCount()
Returns the number of installed CUDA-enabled devices. Use this function before any other GPU functions calls. If OpenCV is compiled without GPU support, this function returns 0.
..index:: gpu::setDevice
gpu::setDevice
------------------
..cpp:function:: void gpu::setDevice(int device)
Sets device and initializes it for the current thread. Call of this function can be omitted, but in this case a default device will be initialized on fist GPU usage.
:param device:index of GPU device in system starting with 0.
..cpp:function:: void setDevice(int device)
Sets a device and initializes it for the current thread. If call of this function is omitted, a default device is initialized at the fist GPU usage.
:param device:System index of a GPU device starting with 0.
..index:: gpu::getDevice
gpu::getDevice
------------------
..cpp:function:: int gpu::getDevice()
Returns the current device index, which was set by :cpp:func:`gpu::setDevice` or initialized by default.
..cpp:function:: int getDevice()
Returns the current device index that was set by {gpu::getDevice} or initialized by default.
..index:: gpu::GpuFeature
gpu::GpuFeature
---------------
..c:type:: gpu::GpuFeature
GPU compute features. ::
This class provides GPU computing features.
::
enum GpuFeature
{
@ -54,16 +47,16 @@ GPU compute features. ::
};
..index:: gpu::DeviceInfo
gpu::DeviceInfo
---------------
..cpp:class:: gpu::DeviceInfo
This class provides functionality for querying the specified GPU properties. ::
This class provides functionality for querying the specified GPU properties.
::
class DeviceInfo
class CV_EXPORTS DeviceInfo
{
public:
DeviceInfo();
@ -84,20 +77,18 @@ This class provides functionality for querying the specified GPU properties. ::
Constructs :cpp:class:`gpu::DeviceInfo` object for the specified device. If ``device_id`` parameter is missed it constructs object for the current device.
:param device_id:Index of the GPU device in system starting with 0.
Constructs the ``DeviceInfo`` object for the specified device. If ``device_id`` parameter is missed, it constructs an object for the current device.
:param device_id:System index of the GPU device starting with 0.
Returns true if the GPU module can be run on the specified device, otherwise false.
Checks the GPU module and device compatibility. This function returns true if the GPU module can be run on the specified device, otherwise returns false.
..index:: gpu::TargetArchs
.._gpu::TargetArchs:
gpu::TargetArchs
----------------
..cpp:class:: gpu::TargetArchs
This class provides functionality (as set of static methods) for checking which NVIDIA card architectures the GPU module was built for.
This class provides a set of static methods to check what NVIDIA card architecture the GPU module was built for.
The following method checks whether the module was built with the support of the given feature:
:param feature:Feature to be checked. See :c:type:`gpu::GpuFeature`.
:param feature:Feature to be checked. See ?.
There are a set of methods for checking whether the module contains intermediate (PTX) or binary GPU code for the given architecture(s):
There is a set of methods to check whether the module contains intermediate (PTX) or binary GPU code for the given architecture(s):
..cpp:function:: static bool gpu::TargetArchs::has(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::has(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasPtx(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasPtx(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasBin(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasBin(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrLessPtx(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrLessPtx(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrGreater(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrGreater(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrGreaterPtx(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrGreaterPtx(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrGreaterBin(int major, int minor)
..cpp:function:: static bool gpu::TargetArchs::hasEqualOrGreaterBin(int major, int minor)
:param major:Major compute capability version.
* **major** Major compute capability version.
:param minor:Minor compute capability version.
According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute capability can always be compiled to binary code of greater or equal compute capability".
* **minor** Minor compute capability version.
According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute capability can always be compiled to binary code of greater or equal compute capability".