Commit 44eaeee8 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored gpu BruteForceMather (made it similar to BFMatcher)

parent c2935a65
......@@ -1220,12 +1220,10 @@ protected:
////////////////////////////////// BruteForceMatcher //////////////////////////////////
class CV_EXPORTS BruteForceMatcher_GPU_base
class CV_EXPORTS BFMatcher_GPU
{
public:
enum DistType {L1Dist = 0, L2Dist, HammingDist};
explicit BruteForceMatcher_GPU_base(DistType distType = L2Dist);
explicit BFMatcher_GPU(int norm = cv::NORM_L2);
// Add descriptors to train descriptor collection
void add(const std::vector<GpuMat>& descCollection);
......@@ -1367,36 +1365,12 @@ public:
void radiusMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, float maxDistance,
const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
DistType distType;
int norm;
private:
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() : BruteForceMatcher_GPU_base(L1Dist) {}
explicit BruteForceMatcher_GPU(L1<T> /*d*/) : BruteForceMatcher_GPU_base(L1Dist) {}
};
template <typename T>
class CV_EXPORTS BruteForceMatcher_GPU< L2<T> > : public BruteForceMatcher_GPU_base
{
public:
explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(L2Dist) {}
explicit BruteForceMatcher_GPU(L2<T> /*d*/) : BruteForceMatcher_GPU_base(L2Dist) {}
};
template <> class CV_EXPORTS BruteForceMatcher_GPU< Hamming > : public BruteForceMatcher_GPU_base
{
public:
explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(HammingDist) {}
explicit BruteForceMatcher_GPU(Hamming /*d*/) : BruteForceMatcher_GPU_base(HammingDist) {}
};
////////////////////////////////// CascadeClassifier_GPU //////////////////////////////////////////
// The cascade classifier class for object detection.
class CV_EXPORTS CascadeClassifier_GPU
......
......@@ -21,7 +21,7 @@ GPU_PERF_TEST(BruteForceMatcher_match, cv::gpu::DeviceInfo, int)
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, distance;
cv::gpu::BruteForceMatcher_GPU< cv::L2<float> > matcher;
cv::gpu::BFMatcher_GPU matcher(cv::NORM_L2);
declare.time(3.0);
......@@ -55,7 +55,7 @@ GPU_PERF_TEST(BruteForceMatcher_knnMatch, cv::gpu::DeviceInfo, int, int)
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, distance, allDist;
cv::gpu::BruteForceMatcher_GPU< cv::L2<float> > matcher;
cv::gpu::BFMatcher_GPU matcher(cv::NORM_L2);
declare.time(3.0);
......@@ -90,7 +90,7 @@ GPU_PERF_TEST(BruteForceMatcher_radiusMatch, cv::gpu::DeviceInfo, int)
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, nMatches, distance;
cv::gpu::BruteForceMatcher_GPU< cv::L2<float> > matcher;
cv::gpu::BFMatcher_GPU matcher(cv::NORM_L2);
declare.time(3.0);
......
This diff is collapsed.
......@@ -503,13 +503,12 @@ INSTANTIATE_TEST_CASE_P(GPU_Features2D, ORB, testing::Combine(
/////////////////////////////////////////////////////////////////////////////////////////////////
// BruteForceMatcher
CV_ENUM(DistType, cv::gpu::BruteForceMatcher_GPU_base::L1Dist, cv::gpu::BruteForceMatcher_GPU_base::L2Dist, cv::gpu::BruteForceMatcher_GPU_base::HammingDist)
IMPLEMENT_PARAM_CLASS(DescriptorSize, int)
PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, DescriptorSize)
PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, NormCode, DescriptorSize)
{
cv::gpu::DeviceInfo devInfo;
cv::gpu::BruteForceMatcher_GPU_base::DistType distType;
int normCode;
int dim;
int queryDescCount;
......@@ -520,7 +519,7 @@ PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, DescriptorSize
virtual void SetUp()
{
devInfo = GET_PARAM(0);
distType = (cv::gpu::BruteForceMatcher_GPU_base::DistType)(int)GET_PARAM(1);
normCode = GET_PARAM(1);
dim = GET_PARAM(2);
cv::gpu::setDevice(devInfo.deviceID());
......@@ -566,7 +565,7 @@ PARAM_TEST_CASE(BruteForceMatcher, cv::gpu::DeviceInfo, DistType, DescriptorSize
TEST_P(BruteForceMatcher, Match)
{
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
cv::gpu::BFMatcher_GPU matcher(normCode);
std::vector<cv::DMatch> matches;
matcher.match(loadMat(query), loadMat(train), matches);
......@@ -584,10 +583,9 @@ TEST_P(BruteForceMatcher, Match)
ASSERT_EQ(0, badCount);
}
TEST_P(BruteForceMatcher, MatchAdd)
{
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::GpuMat d_train(train);
......@@ -638,9 +636,9 @@ TEST_P(BruteForceMatcher, MatchAdd)
TEST_P(BruteForceMatcher, KnnMatch2)
{
const int knn = 2;
cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
const int knn = 2;
std::vector< std::vector<cv::DMatch> > matches;
matcher.knnMatch(loadMat(query), loadMat(train), matches, knn);
......@@ -670,7 +668,7 @@ TEST_P(BruteForceMatcher, KnnMatch2)
TEST_P(BruteForceMatcher, KnnMatch3)
{
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
cv::gpu::BFMatcher_GPU matcher(normCode);
const int knn = 3;
......@@ -702,9 +700,9 @@ TEST_P(BruteForceMatcher, KnnMatch3)
TEST_P(BruteForceMatcher, KnnMatchAdd2)
{
const int knn = 2;
cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
const int knn = 2;
cv::gpu::GpuMat d_train(train);
......@@ -761,9 +759,9 @@ TEST_P(BruteForceMatcher, KnnMatchAdd2)
TEST_P(BruteForceMatcher, KnnMatchAdd3)
{
const int knn = 3;
cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
const int knn = 3;
cv::gpu::GpuMat d_train(train);
......@@ -819,9 +817,9 @@ TEST_P(BruteForceMatcher, KnnMatchAdd3)
TEST_P(BruteForceMatcher, RadiusMatch)
{
const float radius = 1.f / countFactor;
cv::gpu::BFMatcher_GPU matcher(normCode);
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
const float radius = 1.f / countFactor;
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS))
{
......@@ -861,11 +859,11 @@ TEST_P(BruteForceMatcher, RadiusMatch)
TEST_P(BruteForceMatcher, RadiusMatchAdd)
{
cv::gpu::BFMatcher_GPU matcher(normCode);
const int n = 3;
const float radius = 1.f / countFactor * n;
cv::gpu::BruteForceMatcher_GPU_base matcher(distType);
cv::gpu::GpuMat d_train(train);
// make add() twice to test such case
......@@ -936,7 +934,7 @@ TEST_P(BruteForceMatcher, RadiusMatchAdd)
INSTANTIATE_TEST_CASE_P(GPU_Features2D, BruteForceMatcher, testing::Combine(
ALL_DEVICES,
testing::Values(DistType(cv::gpu::BruteForceMatcher_GPU_base::L1Dist), DistType(cv::gpu::BruteForceMatcher_GPU_base::L2Dist)),
testing::Values(NormCode(cv::NORM_L1), NormCode(cv::NORM_L2)),
testing::Values(DescriptorSize(57), DescriptorSize(64), DescriptorSize(83), DescriptorSize(128), DescriptorSize(179), DescriptorSize(256), DescriptorSize(304))));
} // namespace
......@@ -219,7 +219,7 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
descriptors1_.upload(features1.descriptors);
descriptors2_.upload(features2.descriptors);
BruteForceMatcher_GPU< L2<float> > matcher;
BFMatcher_GPU matcher(NORM_L2);
MatchesSet matches;
// Find 1->2 matches
......
......@@ -363,7 +363,7 @@ TEST(BruteForceMatcher)
// Init GPU matcher
gpu::BruteForceMatcher_GPU< L2<float> > d_matcher;
gpu::BFMatcher_GPU d_matcher(NORM_L2);
gpu::GpuMat d_query(query);
gpu::GpuMat d_train(train);
......
......@@ -57,7 +57,7 @@ int main(int argc, char* argv[])
cout << "FOUND " << keypoints2GPU.cols << " keypoints on second image" << endl;
// matching descriptors
BruteForceMatcher_GPU< L2<float> > matcher;
BFMatcher_GPU matcher(NORM_L2);
GpuMat trainIdx, distance;
matcher.matchSingle(descriptors1GPU, descriptors2GPU, trainIdx, distance);
......@@ -69,7 +69,7 @@ int main(int argc, char* argv[])
surf.downloadKeypoints(keypoints2GPU, keypoints2);
surf.downloadDescriptors(descriptors1GPU, descriptors1);
surf.downloadDescriptors(descriptors2GPU, descriptors2);
BruteForceMatcher_GPU< L2<float> >::matchDownload(trainIdx, distance, matches);
BFMatcher_GPU::matchDownload(trainIdx, distance, matches);
// drawing the results
Mat img_matches;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment