From: Alexander Alekhin Date: Fri, 21 Feb 2014 13:58:33 +0000 (+0400) Subject: stitching: allow to use dynamic DescriptorMatcher X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3303^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6cc1be7e8d6e9628b07f3d347dd32a36f0f7478;p=platform%2Fupstream%2Fopencv.git stitching: allow to use dynamic DescriptorMatcher --- diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 32ccd03..f7aded7 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -1369,6 +1369,21 @@ void _InputArray::getUMatVector(std::vector& umv) const return; } + if( k == UMAT ) + { + UMat& v = *(UMat*)obj; + umv.resize(1); + umv[0] = v; + return; + } + if( k == MAT ) + { + Mat& v = *(Mat*)obj; + umv.resize(1); + umv[0] = v.getUMat(accessFlags); + return; + } + CV_Error(Error::StsNotImplemented, "Unknown/unsupported array type"); } diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 91ee9d9..2b56050 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -330,7 +330,7 @@ static bool ocl_match2Dispatcher(InputArray query, InputArray train, const UMat static bool ocl_kmatchDispatcher(InputArray query, InputArray train, const UMat &trainIdx, const UMat &distance, int distType) { - return ocl_match2Dispatcher(query, train, trainIdx, distance, distType); + return ocl_match2Dispatcher(query, train, trainIdx, distance, distType); } static bool ocl_knnMatchSingle(InputArray query, InputArray train, UMat &trainIdx, @@ -1209,8 +1209,8 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr& _indexParam void FlannBasedMatcher::add( InputArrayOfArrays _descriptors ) { DescriptorMatcher::add( _descriptors ); - std::vector descriptors; - _descriptors.getMatVector(descriptors); + std::vector descriptors; + _descriptors.getUMatVector(descriptors); for( size_t i = 0; i < descriptors.size(); i++ ) { diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index ceb3d3d..c303c4a 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -155,21 +155,31 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat matches_info.matches.clear(); - Ptr indexParams = makePtr(); - Ptr searchParams = makePtr(); - - if (features2.descriptors.depth() == CV_8U) + Ptr matcher; +#if 0 // TODO check this + if (ocl::useOpenCL()) { - indexParams->setAlgorithm(cvflann::FLANN_INDEX_LSH); - searchParams->setAlgorithm(cvflann::FLANN_INDEX_LSH); + matcher = makePtr((int)NORM_L2); } + else +#endif + { + Ptr indexParams = makePtr(); + Ptr searchParams = makePtr(); - FlannBasedMatcher matcher(indexParams, searchParams); + if (features2.descriptors.depth() == CV_8U) + { + indexParams->setAlgorithm(cvflann::FLANN_INDEX_LSH); + searchParams->setAlgorithm(cvflann::FLANN_INDEX_LSH); + } + + matcher = makePtr(indexParams, searchParams); + } std::vector< std::vector > pair_matches; MatchesSet matches; // Find 1->2 matches - matcher.knnMatch(features1.descriptors, features2.descriptors, pair_matches, 2); + matcher->knnMatch(features1.descriptors, features2.descriptors, pair_matches, 2); for (size_t i = 0; i < pair_matches.size(); ++i) { if (pair_matches[i].size() < 2) @@ -186,7 +196,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat // Find 2->1 matches pair_matches.clear(); - matcher.knnMatch(features2.descriptors, features1.descriptors, pair_matches, 2); + matcher->knnMatch(features2.descriptors, features1.descriptors, pair_matches, 2); for (size_t i = 0; i < pair_matches.size(); ++i) { if (pair_matches[i].size() < 2)