Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
8891acb6
Commit
8891acb6
authored
Dec 06, 2010
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added BruteForceMatcher_GPU
parent
77027f60
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
326 additions
and
3 deletions
+326
-3
CMakeLists.txt
modules/gpu/CMakeLists.txt
+1
-1
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+147
-1
brute_force_matcher.cpp
modules/gpu/src/brute_force_matcher.cpp
+0
-0
brute_force_matcher.cu
modules/gpu/src/cuda/brute_force_matcher.cu
+0
-0
brute_force_matcher.cpp
tests/gpu/src/brute_force_matcher.cpp
+176
-0
gputest.hpp
tests/gpu/src/gputest.hpp
+2
-1
No files found.
modules/gpu/CMakeLists.txt
View file @
8891acb6
set
(
name
"gpu"
)
set
(
DEPS
"opencv_core"
"opencv_imgproc"
"opencv_objdetect"
)
set
(
DEPS
"opencv_core"
"opencv_imgproc"
"opencv_objdetect"
"opencv_features2d"
"opencv_flann"
)
set
(
OPENCV_LINKER_LIBS
${
OPENCV_LINKER_LIBS
}
opencv_gpu
)
...
...
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
8891acb6
...
...
@@ -48,6 +48,7 @@
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/gpu/devmem2d.hpp"
#include "opencv2/features2d/features2d.hpp"
namespace
cv
{
...
...
@@ -1118,7 +1119,152 @@ namespace cv
// Gradients conputation results
GpuMat
grad
,
qangle
;
};
};
////////////////////////////////// BruteForceMatcher //////////////////////////////////
class
CV_EXPORTS
BruteForceMatcher_GPU_base
{
public
:
enum
DistType
{
L1Dist
=
0
,
L2Dist
};
explicit
BruteForceMatcher_GPU_base
(
DistType
distType
=
L2Dist
);
// Add descriptors to train descriptor collection.
void
add
(
const
std
::
vector
<
GpuMat
>&
descCollection
);
// Get train descriptors collection.
const
std
::
vector
<
GpuMat
>&
getTrainDescriptors
()
const
;
// Clear train descriptors collection.
void
clear
();
// Return true if there are not train descriptors in collection.
bool
empty
()
const
;
// Return true if the matcher supports mask in match methods.
bool
isMaskSupported
()
const
;
// Find one best match for each query descriptor.
// trainIdx.at<int>(0, queryIdx) will contain best train index for queryIdx
// distance.at<float>(0, queryIdx) will contain distance
void
matchSingle
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainDescs
,
GpuMat
&
trainIdx
,
GpuMat
&
distance
,
const
GpuMat
&
mask
=
GpuMat
());
// Download trainIdx and distance to CPU vector with DMatch
static
void
matchDownload
(
const
GpuMat
&
trainIdx
,
const
GpuMat
&
distance
,
std
::
vector
<
DMatch
>&
matches
);
// Find one best match for each query descriptor.
void
match
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainDescs
,
std
::
vector
<
DMatch
>&
matches
,
const
GpuMat
&
mask
=
GpuMat
());
// Make gpu collection of trains and masks in suitable format for matchCollection function
void
makeGpuCollection
(
GpuMat
&
trainCollection
,
GpuMat
&
maskCollection
,
const
vector
<
GpuMat
>&
masks
=
std
::
vector
<
GpuMat
>
());
// Find one best match from train collection for each query descriptor.
// trainIdx.at<int>(0, queryIdx) will contain best train index for queryIdx
// imgIdx.at<int>(0, queryIdx) will contain best image index for queryIdx
// distance.at<float>(0, queryIdx) will contain distance
void
matchCollection
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainCollection
,
GpuMat
&
trainIdx
,
GpuMat
&
imgIdx
,
GpuMat
&
distance
,
const
GpuMat
&
maskCollection
);
// Download trainIdx, imgIdx and distance to CPU vector with DMatch
static
void
matchDownload
(
const
GpuMat
&
trainIdx
,
GpuMat
&
imgIdx
,
const
GpuMat
&
distance
,
std
::
vector
<
DMatch
>&
matches
);
// Find one best match from train collection for each query descriptor.
void
match
(
const
GpuMat
&
queryDescs
,
std
::
vector
<
DMatch
>&
matches
,
const
std
::
vector
<
GpuMat
>&
masks
=
std
::
vector
<
GpuMat
>
());
// Find k best matches for each query descriptor (in increasing order of distances).
// trainIdx.at<int>(queryIdx, i) will contain index of i'th best trains (i < k).
// distance.at<float>(queryIdx, i) will contain distance.
// allDist is a buffer to store all distance between query descriptors and train descriptors
// it have size (nQuery,nTrain) and CV_32F 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
void
knnMatch
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainDescs
,
GpuMat
&
trainIdx
,
GpuMat
&
distance
,
GpuMat
&
allDist
,
int
k
,
const
GpuMat
&
mask
=
GpuMat
());
// Download trainIdx and distance to CPU vector with DMatch
// compactResult is used when mask is not empty. If compactResult is false matches
// vector will have the same size as queryDescriptors rows. If compactResult is true
// matches vector will not contain matches for fully masked out query descriptors.
static
void
knnMatchDownload
(
const
GpuMat
&
trainIdx
,
const
GpuMat
&
distance
,
std
::
vector
<
std
::
vector
<
DMatch
>
>&
matches
,
bool
compactResult
=
false
);
// Find k best matches for each query descriptor (in increasing order of distances).
// compactResult is used when mask is not empty. If compactResult is false matches
// vector will have the same size as queryDescriptors rows. If compactResult is true
// matches vector will not contain matches for fully masked out query descriptors.
void
knnMatch
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainDescs
,
std
::
vector
<
std
::
vector
<
DMatch
>
>&
matches
,
int
k
,
const
GpuMat
&
mask
=
GpuMat
(),
bool
compactResult
=
false
);
// Find k best matches for each query descriptor (in increasing order of distances).
// compactResult is used when mask is not empty. If compactResult is false matches
// vector will have the same size as queryDescriptors rows. If compactResult is true
// matches vector will not contain matches for fully masked out query descriptors.
void
knnMatch
(
const
GpuMat
&
queryDescs
,
std
::
vector
<
std
::
vector
<
DMatch
>
>&
matches
,
int
knn
,
const
std
::
vector
<
GpuMat
>&
masks
=
std
::
vector
<
GpuMat
>
(),
bool
compactResult
=
false
);
// Find best matches for each query descriptor which have distance less than maxDistance.
// nMatches.at<unsigned int>(0, queruIdx) 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.
// trainIdx.at<int>(queruIdx, i) will contain ith train index (i < min(nMatches.at<unsigned int>(0, queruIdx), trainIdx.cols))
// distance.at<int>(queruIdx, i) will contain ith distance (i < min(nMatches.at<unsigned int>(0, queruIdx), trainIdx.cols))
// If trainIdx is empty, then trainIdx and distance will be created with size nQuery x nTrain,
// otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
// Matches doesn't sorted.
void
radiusMatch
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainDescs
,
GpuMat
&
trainIdx
,
GpuMat
&
nMatches
,
GpuMat
&
distance
,
float
maxDistance
,
const
GpuMat
&
mask
=
GpuMat
());
// Download trainIdx, nMatches and distance to CPU vector with DMatch.
// matches will be sorted in increasing order of distances.
// compactResult is used when mask is not empty. If compactResult is false matches
// vector will have the same size as queryDescriptors rows. If compactResult is true
// matches vector will not contain matches for fully masked out query descriptors.
static
void
radiusMatchDownload
(
const
GpuMat
&
trainIdx
,
const
GpuMat
&
nMatches
,
const
GpuMat
&
distance
,
std
::
vector
<
std
::
vector
<
DMatch
>
>&
matches
,
bool
compactResult
=
false
);
// Find best matches for each query descriptor which have distance less than maxDistance
// in increasing order of distances).
void
radiusMatch
(
const
GpuMat
&
queryDescs
,
const
GpuMat
&
trainDescs
,
std
::
vector
<
std
::
vector
<
DMatch
>
>&
matches
,
float
maxDistance
,
const
GpuMat
&
mask
=
GpuMat
(),
bool
compactResult
=
false
);
// Find best matches from train collection for each query descriptor which have distance less than
// maxDistance (in increasing order of distances).
void
radiusMatch
(
const
GpuMat
&
queryDescs
,
std
::
vector
<
std
::
vector
<
DMatch
>
>&
matches
,
float
maxDistance
,
const
std
::
vector
<
GpuMat
>&
masks
=
std
::
vector
<
GpuMat
>
(),
bool
compactResult
=
false
);
private
:
DistType
distType
;
std
::
vector
<
GpuMat
>
trainDescCollection
;
};
template
<
class
Distance
>
class
CV_EXPORTS
BruteForceMatcher_GPU
;
template
<
typename
T
>
class
CV_EXPORTS
BruteForceMatcher_GPU
<
L1
<
T
>
>
:
public
BruteForceMatcher_GPU_base
{
public
:
explicit
BruteForceMatcher_GPU
(
L1
<
T
>
d
=
L1
<
T
>
())
:
BruteForceMatcher_GPU_base
(
L1Dist
)
{}
};
template
<
typename
T
>
class
CV_EXPORTS
BruteForceMatcher_GPU
<
L2
<
T
>
>
:
public
BruteForceMatcher_GPU_base
{
public
:
explicit
BruteForceMatcher_GPU
(
L2
<
T
>
d
=
L2
<
T
>
())
:
BruteForceMatcher_GPU_base
(
L2Dist
)
{}
};
}
...
...
modules/gpu/src/brute_force_matcher.cpp
0 → 100644
View file @
8891acb6
This diff is collapsed.
Click to expand it.
modules/gpu/src/cuda/brute_force_matcher.cu
0 → 100644
View file @
8891acb6
This diff is collapsed.
Click to expand it.
tests/gpu/src/brute_force_matcher.cpp
0 → 100644
View file @
8891acb6
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "gputest.hpp"
using
namespace
cv
;
using
namespace
cv
::
gpu
;
using
namespace
std
;
class
CV_GpuBruteForceMatcherTest
:
public
CvTest
{
public
:
CV_GpuBruteForceMatcherTest
()
:
CvTest
(
"GPU-BruteForceMatcher"
,
"BruteForceMatcher"
)
{}
protected
:
void
run
(
int
)
{
try
{
BruteForceMatcher
<
L2
<
float
>
>
matcherCPU
;
BruteForceMatcher_GPU
<
L2
<
float
>
>
matcherGPU
;
vector
<
DMatch
>
matchesCPU
,
matchesGPU
;
vector
<
vector
<
DMatch
>
>
knnMatchesCPU
,
knnMatchesGPU
;
vector
<
vector
<
DMatch
>
>
radiusMatchesCPU
,
radiusMatchesGPU
;
RNG
rng
(
*
ts
->
get_rng
());
const
int
desc_len
=
rng
.
uniform
(
40
,
300
);
Mat
queryCPU
(
rng
.
uniform
(
100
,
300
),
desc_len
,
CV_32F
);
rng
.
fill
(
queryCPU
,
cv
::
RNG
::
UNIFORM
,
cv
::
Scalar
::
all
(
0.0
),
cv
::
Scalar
::
all
(
1.0
));
GpuMat
queryGPU
(
queryCPU
);
const
int
nTrains
=
rng
.
uniform
(
1
,
5
);
vector
<
Mat
>
trainsCPU
(
nTrains
);
vector
<
GpuMat
>
trainsGPU
(
nTrains
);
vector
<
Mat
>
masksCPU
(
nTrains
);
vector
<
GpuMat
>
masksGPU
(
nTrains
);
for
(
int
i
=
0
;
i
<
nTrains
;
++
i
)
{
Mat
train
(
rng
.
uniform
(
100
,
300
),
desc_len
,
CV_32F
);
rng
.
fill
(
train
,
cv
::
RNG
::
UNIFORM
,
cv
::
Scalar
::
all
(
0.0
),
cv
::
Scalar
::
all
(
1.0
));
trainsCPU
[
i
]
=
train
;
trainsGPU
[
i
].
upload
(
train
);
bool
with_mask
=
rng
.
uniform
(
0
,
10
)
<
5
;
if
(
with_mask
)
{
Mat
mask
(
queryCPU
.
rows
,
train
.
rows
,
CV_8U
,
Scalar
::
all
(
1
));
rng
.
fill
(
mask
,
cv
::
RNG
::
UNIFORM
,
cv
::
Scalar
::
all
(
0
),
cv
::
Scalar
::
all
(
200
));
masksCPU
[
i
]
=
mask
;
masksGPU
[
i
].
upload
(
mask
);
}
}
matcherCPU
.
add
(
trainsCPU
);
matcherGPU
.
add
(
trainsGPU
);
matcherCPU
.
match
(
queryCPU
,
matchesCPU
,
masksCPU
);
matcherGPU
.
match
(
queryGPU
,
matchesGPU
,
masksGPU
);
if
(
!
compareMatches
(
matchesCPU
,
matchesGPU
))
{
ts
->
set_failed_test_info
(
CvTS
::
FAIL_MISMATCH
);
return
;
}
const
int
knn
=
rng
.
uniform
(
3
,
10
);
matcherCPU
.
knnMatch
(
queryCPU
,
knnMatchesCPU
,
knn
,
masksCPU
);
matcherGPU
.
knnMatch
(
queryGPU
,
knnMatchesGPU
,
knn
,
masksGPU
);
if
(
!
compareMatches
(
knnMatchesCPU
,
knnMatchesGPU
))
{
ts
->
set_failed_test_info
(
CvTS
::
FAIL_MISMATCH
);
return
;
}
const
float
maxDistance
=
rng
.
uniform
(
0.01
f
,
0.3
f
);
matcherCPU
.
radiusMatch
(
queryCPU
,
radiusMatchesCPU
,
maxDistance
,
masksCPU
);
matcherGPU
.
radiusMatch
(
queryGPU
,
radiusMatchesGPU
,
maxDistance
,
masksGPU
);
if
(
!
compareMatches
(
radiusMatchesCPU
,
radiusMatchesGPU
))
{
ts
->
set_failed_test_info
(
CvTS
::
FAIL_MISMATCH
);
return
;
}
}
catch
(
const
cv
::
Exception
&
e
)
{
if
(
!
check_and_treat_gpu_exception
(
e
,
ts
))
throw
;
return
;
}
ts
->
set_failed_test_info
(
CvTS
::
OK
);
}
private
:
static
void
convertMatches
(
const
vector
<
vector
<
DMatch
>
>&
knnMatches
,
vector
<
DMatch
>&
matches
)
{
matches
.
clear
();
for
(
size_t
i
=
0
;
i
<
knnMatches
.
size
();
++
i
)
copy
(
knnMatches
[
i
].
begin
(),
knnMatches
[
i
].
end
(),
back_inserter
(
matches
));
}
static
bool
compareMatches
(
const
vector
<
DMatch
>&
matches1
,
const
vector
<
DMatch
>&
matches2
)
{
if
(
matches1
.
size
()
!=
matches2
.
size
())
return
false
;
struct
DMatchEqual
:
public
binary_function
<
DMatch
,
DMatch
,
bool
>
{
bool
operator
()(
const
DMatch
&
m1
,
const
DMatch
&
m2
)
{
return
m1
.
imgIdx
==
m2
.
imgIdx
&&
m1
.
queryIdx
==
m2
.
queryIdx
&&
m1
.
trainIdx
==
m2
.
trainIdx
;
}
};
return
equal
(
matches1
.
begin
(),
matches1
.
end
(),
matches2
.
begin
(),
DMatchEqual
());
}
static
bool
compareMatches
(
const
vector
<
vector
<
DMatch
>
>&
matches1
,
const
vector
<
vector
<
DMatch
>
>&
matches2
)
{
vector
<
DMatch
>
m1
,
m2
;
convertMatches
(
matches1
,
m1
);
convertMatches
(
matches2
,
m2
);
return
compareMatches
(
m1
,
m2
);
}
}
brute_force_matcher_test
;
\ No newline at end of file
tests/gpu/src/gputest.hpp
View file @
8891acb6
...
...
@@ -50,7 +50,8 @@
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include "cxts.h"
/****************************************************************************************/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment