opencv/modules/gpu/doc/feature_detection_and_description.rst

356 lines
18 KiB
ReStructuredText
Raw Normal View History

Feature Detection and Description
=================================
.. highlight:: cpp
.. index:: gpu::SURF_GPU
2011-03-03 08:29:55 +01:00
.. gpu::SURF_GPU:
gpu::SURF_GPU
-------------
.. c:type:: gpu::SURF_GPU
2011-02-26 12:05:10 +01:00
Class for extracting Speeded Up Robust Features from an image. ::
2011-03-14 08:04:41 +01:00
class SURF_GPU : public CvSURFParams
2011-02-26 12:05:10 +01:00
{
public:
2011-03-14 08:04:41 +01:00
//! the default constructor
SURF_GPU();
//! the full constructor taking all the necessary parameters
explicit SURF_GPU(double _hessianThreshold, int _nOctaves=4,
int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f);
2011-02-26 12:05:10 +01:00
//! returns the descriptor size in float's (64 or 128)
int descriptorSize() const;
//! upload host keypoints to device memory
2011-03-14 08:04:41 +01:00
void uploadKeypoints(const vector<KeyPoint>& keypoints,
2011-02-26 12:05:10 +01:00
GpuMat& keypointsGPU);
//! download keypoints from device to host memory
2011-03-14 08:04:41 +01:00
void downloadKeypoints(const GpuMat& keypointsGPU,
2011-02-26 12:05:10 +01:00
vector<KeyPoint>& keypoints);
//! download descriptors from device to host memory
2011-03-14 08:04:41 +01:00
void downloadDescriptors(const GpuMat& descriptorsGPU,
2011-02-26 12:05:10 +01:00
vector<float>& descriptors);
void operator()(const GpuMat& img, const GpuMat& mask,
GpuMat& keypoints);
void operator()(const GpuMat& img, const GpuMat& mask,
GpuMat& keypoints, GpuMat& descriptors,
bool useProvidedKeypoints = false,
bool calcOrientation = true);
void operator()(const GpuMat& img, const GpuMat& mask,
std::vector<KeyPoint>& keypoints);
void operator()(const GpuMat& img, const GpuMat& mask,
std::vector<KeyPoint>& keypoints, GpuMat& descriptors,
bool useProvidedKeypoints = false,
bool calcOrientation = true);
void operator()(const GpuMat& img, const GpuMat& mask,
std::vector<KeyPoint>& keypoints,
std::vector<float>& descriptors,
bool useProvidedKeypoints = false,
bool calcOrientation = true);
2011-03-14 08:04:41 +01:00
//! max keypoints = keypointsRatio * img.size().area()
float keypointsRatio;
GpuMat sum, mask1, maskSum, intBuffer;
2011-02-26 12:05:10 +01:00
2011-03-14 08:04:41 +01:00
GpuMat det, trace;
2011-02-26 12:05:10 +01:00
GpuMat maxPosBuffer;
GpuMat featuresBuffer;
2011-03-14 08:04:41 +01:00
GpuMat keypointsBuffer;
2011-02-26 12:05:10 +01:00
};
2011-02-26 12:05:10 +01:00
The class ``SURF_GPU`` implements Speeded Up Robust Features descriptor. There is fast multi-scale Hessian keypoint detector that can be used to find the keypoints (which is the default option), but the descriptors can be also computed for the user-specified keypoints. Supports only 8 bit grayscale images.
2011-03-14 08:04:41 +01:00
The class ``SURF_GPU`` can store results to GPU and CPU memory and provides functions to convert results between CPU and GPU version ( ``uploadKeypoints``,``downloadKeypoints``,``downloadDescriptors`` ). CPU results has the same format as ``SURF``
results. GPU results are stored to ``GpuMat`` . ``keypoints`` matrix is one row matrix with ``CV_32FC6`` type. It contains 6 float values per feature: ``x, y, laplacian, size, dir, hessian`` . ``descriptors`` matrix is
2011-02-26 12:05:10 +01:00
:math:`\texttt{nFeatures} \times \texttt{descriptorSize}` matrix with ``CV_32FC1`` type.
2011-02-26 12:05:10 +01:00
The class ``SURF_GPU`` uses some buffers and provides access to it. All buffers can be safely released between function calls.
See also:
.
.. index:: gpu::BruteForceMatcher_GPU
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU:
gpu::BruteForceMatcher_GPU
--------------------------
.. c:type:: gpu::BruteForceMatcher_GPU
2011-02-26 12:05:10 +01:00
Brute-force descriptor matcher. For each descriptor in the first set, this matcher finds the closest descriptor in the second set by trying each one. This descriptor matcher supports masking permissible matches between descriptor sets. ::
2011-02-26 12:05:10 +01:00
template<class Distance>
class BruteForceMatcher_GPU
{
public:
// Add descriptors to train descriptor collection.
void add(const std::vector<GpuMat>& descCollection);
2011-02-26 12:05:10 +01:00
// Get train descriptors collection.
const std::vector<GpuMat>& getTrainDescriptors() const;
2011-02-26 12:05:10 +01:00
// Clear train descriptors collection.
void clear();
2011-02-26 12:05:10 +01:00
// Return true if there are not train descriptors in collection.
bool empty() const;
2011-02-26 12:05:10 +01:00
// Return true if the matcher supports mask in match methods.
bool isMaskSupported() const;
2011-02-26 12:05:10 +01:00
void matchSingle(const GpuMat& queryDescs, const GpuMat& trainDescs,
GpuMat& trainIdx, GpuMat& distance,
const GpuMat& mask = GpuMat());
2011-02-26 12:05:10 +01:00
static void matchDownload(const GpuMat& trainIdx,
const GpuMat& distance, std::vector<DMatch>& matches);
2011-02-26 12:05:10 +01:00
void match(const GpuMat& queryDescs, const GpuMat& trainDescs,
std::vector<DMatch>& matches, const GpuMat& mask = GpuMat());
2011-02-26 12:05:10 +01:00
void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection,
const vector<GpuMat>& masks = std::vector<GpuMat>());
2011-02-26 12:05:10 +01:00
void matchCollection(const GpuMat& queryDescs,
const GpuMat& trainCollection,
GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
const GpuMat& maskCollection);
2011-02-26 12:05:10 +01:00
static void matchDownload(const GpuMat& trainIdx, GpuMat& imgIdx,
const GpuMat& distance, std::vector<DMatch>& matches);
2011-02-26 12:05:10 +01:00
void match(const GpuMat& queryDescs, std::vector<DMatch>& matches,
const std::vector<GpuMat>& masks = std::vector<GpuMat>());
2011-02-26 12:05:10 +01:00
void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k,
const GpuMat& mask = GpuMat());
2011-02-26 12:05:10 +01:00
static void knnMatchDownload(const GpuMat& trainIdx,
const GpuMat& distance, std::vector< std::vector<DMatch> >& matches,
bool compactResult = false);
2011-02-26 12:05:10 +01:00
void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
std::vector< std::vector<DMatch> >& matches, int k,
const GpuMat& mask = GpuMat(), bool compactResult = false);
2011-02-26 12:05:10 +01:00
void knnMatch(const GpuMat& queryDescs,
std::vector< std::vector<DMatch> >& matches, int knn,
const std::vector<GpuMat>& masks = std::vector<GpuMat>(),
bool compactResult = false );
2011-02-26 12:05:10 +01:00
void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
GpuMat& trainIdx, GpuMat& nMatches, GpuMat& distance,
float maxDistance, const GpuMat& mask = GpuMat());
2011-02-26 12:05:10 +01:00
static void radiusMatchDownload(const GpuMat& trainIdx,
const GpuMat& nMatches, const GpuMat& distance,
std::vector< std::vector<DMatch> >& matches,
bool compactResult = false);
2011-02-26 12:05:10 +01:00
void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
std::vector< std::vector<DMatch> >& matches, float maxDistance,
const GpuMat& mask = GpuMat(), bool compactResult = false);
2011-02-26 12:05:10 +01:00
void radiusMatch(const GpuMat& queryDescs,
std::vector< std::vector<DMatch> >& matches, float maxDistance,
const std::vector<GpuMat>& masks = std::vector<GpuMat>(),
bool compactResult = false);
2011-02-26 12:05:10 +01:00
private:
std::vector<GpuMat> trainDescCollection;
};
2011-03-03 08:29:55 +01:00
The class ``BruteForceMatcher_GPU`` has the similar interface to class. It has two groups of match methods: for matching descriptors of one image with other image or with image set. Also all functions have alternative: save results to GPU memory or to CPU memory. ``Distance`` template parameter is kept for CPU/GPU interfaces similarity. ``BruteForceMatcher_GPU`` supports only ``L1<float>`` and ``L2<float>`` distance types.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::match
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::match:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::match
2011-02-26 12:05:10 +01:00
-------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void match(const GpuMat&queryDescs, const GpuMat&trainDescs, std::vector<DMatch>&matches, const GpuMat&mask = GpuMat())
2011-03-03 08:29:55 +01:00
.. c:function:: void match(const GpuMat&queryDescs, std::vector<DMatch>&matches, const std::vector<GpuMat>&masks = std::vector<GpuMat>())
2011-02-26 12:05:10 +01:00
Finds the best match for each descriptor from a query set with train descriptors.
2011-02-26 12:05:10 +01:00
See also:
:func:`DescriptorMatcher::match` .
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::matchSingle
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::matchSingle:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::matchSingle
2011-02-26 12:05:10 +01:00
-------------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void matchSingle(const GpuMat&queryDescs, const GpuMat&trainDescs, GpuMat&trainIdx, GpuMat&distance, const GpuMat&mask = GpuMat())
2011-02-26 12:05:10 +01:00
Finds the best match for each query descriptor. Results will be stored to GPU memory.
{Query set of descriptors.}
{Train set of descriptors. This will not be added to train descriptors collection stored in class object.}
{One row ``CV_32SC1`` matrix. Will contain the best train index for each query. If some query descriptors are masked out in ``mask`` it will contain -1.}
{One row ``CV_32FC1`` matrix. Will contain the best distance for each query. If some query descriptors are masked out in ``mask`` it will contain ``FLT_MAX`` .}
2011-02-26 12:05:10 +01:00
:param mask: Mask specifying permissible matches between input query and train matrices of descriptors.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::matchCollection
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::matchCollection:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::matchCollection
-----------------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void matchCollection(const GpuMat&queryDescs, const GpuMat&trainCollection, GpuMat&trainIdx, GpuMat&imgIdx, GpuMat&distance, const GpuMat&maskCollection)
2011-02-26 12:05:10 +01:00
Find the best match for each query descriptor from train collection. Results will be stored to GPU memory.
2011-02-26 12:05:10 +01:00
{Query set of descriptors.}
{ ``GpuMat`` containing train collection. It can be obtained from train descriptors collection that was set using ``add`` method by
. Or it can contain user defined collection. It must be one row matrix, each element is a ``DevMem2D`` that points to one train descriptors matrix.}
{One row ``CV_32SC1`` matrix. Will contain the best train index for each query. If some query descriptors are masked out in ``maskCollection`` it will contain -1.}
{One row ``CV_32SC1`` matrix. Will contain image train index for each query. If some query descriptors are masked out in ``maskCollection`` it will contain -1.}
{One row ``CV_32FC1`` matrix. Will contain the best distance for each query. If some query descriptors are masked out in ``maskCollection`` it will contain ``FLT_MAX`` .}
2011-02-26 12:05:10 +01:00
:param maskCollection: ``GpuMat`` containing set of masks. It can be obtained from ``std::vector<GpuMat>`` by . Or it can contain user defined mask set. It must be empty matrix or one row matrix, each element is a ``PtrStep`` that points to one mask.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::makeGpuCollection
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::makeGpuCollection:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::makeGpuCollection
-------------------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void makeGpuCollection(GpuMat&trainCollection, GpuMat&maskCollection, const vector<GpuMat>&masks = std::vector<GpuMat>())
2011-02-26 12:05:10 +01:00
Makes gpu collection of train descriptors and masks in suitable format for function.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::matchDownload
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::matchDownload:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::matchDownload
---------------------------------------------
.. c:function:: void matchDownload(const GpuMat&trainIdx, const GpuMat&distance, std::vector<DMatch>&matches)
2011-03-03 08:29:55 +01:00
.. c:function:: void matchDownload(const GpuMat&trainIdx, GpuMat&imgIdx, const GpuMat&distance, std::vector<DMatch>&matches)
2011-02-26 12:05:10 +01:00
Downloads trainIdx, imgIdxand distancematrices obtained via or to CPU vector with .
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::knnMatch
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::knnMatch:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::knnMatch
----------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void knnMatch(const GpuMat&queryDescs, const GpuMat&trainDescs, std::vector< std::vector<DMatch> >&matches, int k, const GpuMat&mask = GpuMat(), bool compactResult = false)
2011-02-26 12:05:10 +01:00
Finds the k best matches for each descriptor from a query set with train descriptors. Found k (or less if not possible) matches are returned in distance increasing order.
2011-03-03 08:29:55 +01:00
.. c:function:: void knnMatch(const GpuMat&queryDescs, std::vector< std::vector<DMatch> >&matches, int k, const std::vector<GpuMat>&masks = std::vector<GpuMat>(), bool compactResult = false )
2011-02-26 12:05:10 +01:00
See also:
:func:`DescriptorMatcher::knnMatch` .
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::knnMatch
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::knnMatch:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::knnMatch
----------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void knnMatch(const GpuMat&queryDescs, const GpuMat&trainDescs, GpuMat&trainIdx, GpuMat&distance, GpuMat&allDist, int k, const GpuMat&mask = GpuMat())
2011-02-26 12:05:10 +01:00
Finds the k best matches for each descriptor from a query set with train descriptors. Found k (or less if not possible) matches are returned in distance increasing order. Results will be stored to GPU memory.
2011-02-26 12:05:10 +01:00
{Query set of descriptors.}
{Train set of descriptors. This will not be added to train descriptors collection stored in class object.}
{Matrix with
:math:`\texttt{nQueries} \times \texttt{k}` size and ``CV_32SC1`` type. ``trainIdx.at<int>(queryIdx, i)`` will contain index of the i'th best trains. If some query descriptors are masked out in ``mask`` it will contain -1.}
{Matrix with
:math:`\texttt{nQuery} \times \texttt{k}` and ``CV_32FC1`` type. Will contain distance for each query and the i'th best trains. If some query descriptors are masked out in ``mask`` it will contain ``FLT_MAX`` .}
{Buffer to store all distances between query descriptors and train descriptors. It will have
:math:`\texttt{nQuery} \times \texttt{nTrain}` size and ``CV_32FC1`` type. ``allDist.at<float>(queryIdx, trainIdx)`` will contain ``FLT_MAX`` , if ``trainIdx`` is one from k best, otherwise it will contain distance between ``queryIdx`` and ``trainIdx`` descriptors.}
2011-02-26 12:05:10 +01:00
:param k: Number of the best matches will be found per each query descriptor (or less if it's not possible).
2011-02-26 12:05:10 +01:00
:param mask: Mask specifying permissible matches between input query and train matrices of descriptors.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::knnMatchDownload
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::knnMatchDownload:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::knnMatchDownload
------------------------------------------------
.. c:function:: void knnMatchDownload(const GpuMat&trainIdx, const GpuMat&distance, std::vector< std::vector<DMatch> >&matches, bool compactResult = false)
2011-02-26 12:05:10 +01:00
Downloads trainIdxand distancematrices obtained via to CPU vector with . If compactResultis true matchesvector will not contain matches for fully masked out query descriptors.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::radiusMatch
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::radiusMatch:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::radiusMatch
-------------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void radiusMatch(const GpuMat&queryDescs, const GpuMat&trainDescs, std::vector< std::vector<DMatch> >&matches, float maxDistance, const GpuMat&mask = GpuMat(), bool compactResult = false)
2011-02-26 12:05:10 +01:00
Finds the best matches for each query descriptor which have distance less than given threshold. Found matches are returned in distance increasing order.
2011-03-03 08:29:55 +01:00
.. c:function:: void radiusMatch(const GpuMat&queryDescs, std::vector< std::vector<DMatch> >&matches, float maxDistance, const std::vector<GpuMat>&masks = std::vector<GpuMat>(), bool compactResult = false)
2011-02-26 12:05:10 +01:00
This function works only on devices with Compute Capability
:math:`>=` 1.1.
2011-02-26 12:05:10 +01:00
See also:
:func:`DescriptorMatcher::radiusMatch` .
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::radiusMatch
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::radiusMatch:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::radiusMatch
-------------------------------------------
2011-03-03 08:29:55 +01:00
.. c:function:: void radiusMatch(const GpuMat&queryDescs, const GpuMat&trainDescs, GpuMat&trainIdx, GpuMat&nMatches, GpuMat&distance, float maxDistance, const GpuMat&mask = GpuMat())
2011-02-26 12:05:10 +01:00
Finds the best matches for each query descriptor which have distance less than given threshold. Results will be stored to GPU memory.
2011-02-26 12:05:10 +01:00
{Query set of descriptors.}
{Train set of descriptors. This will not be added to train descriptors collection stored in class object.}
{ ``trainIdx.at<int>(queryIdx, i)`` will contain i'th train index ``(i < min(nMatches.at<unsigned int>(0, queryIdx), trainIdx.cols)`` . If ``trainIdx`` is empty, it will be created with size
:math:`\texttt{nQuery} \times \texttt{nTrain}` . Or it can be allocated by user (it must have ``nQuery`` rows and ``CV_32SC1`` type). Cols can be less than ``nTrain`` , but it can be that matcher won't find all matches, because it haven't enough memory to store results.}
{ ``nMatches.at<unsigned int>(0, queryIdx)`` will contain matches count for ``queryIdx`` . Carefully, ``nMatches`` can be greater than ``trainIdx.cols`` - it means that matcher didn't find all matches, because it didn't have enough memory.}
{ ``distance.at<int>(queryIdx, i)`` will contain i'th distance ``(i < min(nMatches.at<unsigned int>(0, queryIdx), trainIdx.cols)`` . If ``trainIdx`` is empty, it will be created with size
:math:`\texttt{nQuery} \times \texttt{nTrain}` . Otherwise it must be also allocated by user (it must have the same size as ``trainIdx`` and ``CV_32FC1`` type).}
2011-02-26 12:05:10 +01:00
:param maxDistance: Distance threshold.
2011-02-26 12:05:10 +01:00
:param mask: Mask specifying permissible matches between input query and train matrices of descriptors.
2011-03-03 08:29:55 +01:00
In contrast to results are not sorted by distance increasing order.
2011-02-26 12:05:10 +01:00
This function works only on devices with Compute Capability
:math:`>=` 1.1.
2011-03-03 08:29:55 +01:00
.. index:: gpu::BruteForceMatcher_GPU::radiusMatchDownload
2011-03-03 08:29:55 +01:00
.. gpu::BruteForceMatcher_GPU::radiusMatchDownload:
2011-03-03 08:29:55 +01:00
gpu::BruteForceMatcher_GPU::radiusMatchDownload
---------------------------------------------------
.. c:function:: void radiusMatchDownload(const GpuMat&trainIdx, const GpuMat&nMatches, const GpuMat&distance, std::vector< std::vector<DMatch> >&matches, bool compactResult = false)
2011-02-26 12:05:10 +01:00
Downloads trainIdx, nMatchesand distancematrices obtained via to CPU vector with . If compactResultis true matchesvector will not contain matches for fully masked out query descriptors.