|
|
@ -42,25 +42,19 @@ |
|
|
|
#include "precomp.hpp" |
|
|
|
#include "precomp.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
using namespace cv; |
|
|
|
using namespace cv::gpu; |
|
|
|
using namespace cv::gpu; |
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
void cv::FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
find(image, features); |
|
|
|
find(image, features); |
|
|
|
features.img_size = image.size(); |
|
|
|
features.img_size = image.size(); |
|
|
|
//features.img = image.clone();
|
|
|
|
//features.img = image.clone();
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace cv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
using namespace cv; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CpuSurfFeaturesFinder : public FeaturesFinder |
|
|
|
class CpuSurfFeaturesFinder : public FeaturesFinder |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
@ -155,10 +149,7 @@ namespace |
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
cv::SurfFeaturesFinder::SurfFeaturesFinder(bool try_use_gpu, double hess_thresh, int num_octaves, int num_layers, |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SurfFeaturesFinder::SurfFeaturesFinder(bool try_use_gpu, double hess_thresh, int num_octaves, int num_layers,
|
|
|
|
|
|
|
|
int num_octaves_descr, int num_layers_descr) |
|
|
|
int num_octaves_descr, int num_layers_descr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (try_use_gpu && getCudaEnabledDeviceCount() > 0) |
|
|
|
if (try_use_gpu && getCudaEnabledDeviceCount() > 0) |
|
|
@ -168,12 +159,12 @@ SurfFeaturesFinder::SurfFeaturesFinder(bool try_use_gpu, double hess_thresh, int |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) |
|
|
|
void cv::SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) |
|
|
|
{ |
|
|
|
{ |
|
|
|
(*impl_)(image, features); |
|
|
|
(*impl_)(image, features); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SurfFeaturesFinder::releaseMemory() |
|
|
|
void cv::SurfFeaturesFinder::releaseMemory() |
|
|
|
{ |
|
|
|
{ |
|
|
|
impl_->releaseMemory(); |
|
|
|
impl_->releaseMemory(); |
|
|
|
} |
|
|
|
} |
|
|
@ -181,11 +172,11 @@ void SurfFeaturesFinder::releaseMemory() |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
MatchesInfo::MatchesInfo() : src_img_idx(-1), dst_img_idx(-1), num_inliers(0), confidence(0) {} |
|
|
|
cv::MatchesInfo::MatchesInfo() : src_img_idx(-1), dst_img_idx(-1), num_inliers(0), confidence(0) {} |
|
|
|
|
|
|
|
|
|
|
|
MatchesInfo::MatchesInfo(const MatchesInfo &other) { *this = other; } |
|
|
|
cv::MatchesInfo::MatchesInfo(const MatchesInfo &other) { *this = other; } |
|
|
|
|
|
|
|
|
|
|
|
const MatchesInfo& MatchesInfo::operator =(const MatchesInfo &other) |
|
|
|
const cv::MatchesInfo& MatchesInfo::operator =(const MatchesInfo &other) |
|
|
|
{ |
|
|
|
{ |
|
|
|
src_img_idx = other.src_img_idx; |
|
|
|
src_img_idx = other.src_img_idx; |
|
|
|
dst_img_idx = other.dst_img_idx; |
|
|
|
dst_img_idx = other.dst_img_idx; |
|
|
@ -200,65 +191,69 @@ const MatchesInfo& MatchesInfo::operator =(const MatchesInfo &other) |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
struct DistIdxPair |
|
|
|
namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool operator<(const DistIdxPair &other) const { return dist < other.dist; } |
|
|
|
|
|
|
|
double dist; |
|
|
|
|
|
|
|
int idx; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct MatchPairsBody |
|
|
|
struct DistIdxPair |
|
|
|
{ |
|
|
|
{ |
|
|
|
MatchPairsBody(const MatchPairsBody& other) |
|
|
|
bool operator<(const DistIdxPair &other) const { return dist < other.dist; } |
|
|
|
: matcher(other.matcher), features(other.features),
|
|
|
|
double dist; |
|
|
|
pairwise_matches(other.pairwise_matches), near_pairs(other.near_pairs) {} |
|
|
|
int idx; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
MatchPairsBody(FeaturesMatcher &matcher, const vector<ImageFeatures> &features,
|
|
|
|
|
|
|
|
vector<MatchesInfo> &pairwise_matches, vector<pair<int,int> > &near_pairs) |
|
|
|
|
|
|
|
: matcher(matcher), features(features),
|
|
|
|
|
|
|
|
pairwise_matches(pairwise_matches), near_pairs(near_pairs) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void operator ()(const BlockedRange &r) const
|
|
|
|
struct MatchPairsBody |
|
|
|
{ |
|
|
|
{ |
|
|
|
const int num_images = static_cast<int>(features.size()); |
|
|
|
MatchPairsBody(const MatchPairsBody& other) |
|
|
|
for (int i = r.begin(); i < r.end(); ++i) |
|
|
|
: matcher(other.matcher), features(other.features), |
|
|
|
|
|
|
|
pairwise_matches(other.pairwise_matches), near_pairs(other.near_pairs) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MatchPairsBody(FeaturesMatcher &matcher, const vector<ImageFeatures> &features, |
|
|
|
|
|
|
|
vector<MatchesInfo> &pairwise_matches, vector<pair<int,int> > &near_pairs) |
|
|
|
|
|
|
|
: matcher(matcher), features(features), |
|
|
|
|
|
|
|
pairwise_matches(pairwise_matches), near_pairs(near_pairs) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void operator ()(const BlockedRange &r) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
int from = near_pairs[i].first; |
|
|
|
const int num_images = static_cast<int>(features.size()); |
|
|
|
int to = near_pairs[i].second; |
|
|
|
for (int i = r.begin(); i < r.end(); ++i) |
|
|
|
int pair_idx = from*num_images + to; |
|
|
|
{ |
|
|
|
|
|
|
|
int from = near_pairs[i].first; |
|
|
|
|
|
|
|
int to = near_pairs[i].second; |
|
|
|
|
|
|
|
int pair_idx = from*num_images + to; |
|
|
|
|
|
|
|
|
|
|
|
matcher(features[from], features[to], pairwise_matches[pair_idx]); |
|
|
|
matcher(features[from], features[to], pairwise_matches[pair_idx]); |
|
|
|
pairwise_matches[pair_idx].src_img_idx = from; |
|
|
|
pairwise_matches[pair_idx].src_img_idx = from; |
|
|
|
pairwise_matches[pair_idx].dst_img_idx = to; |
|
|
|
pairwise_matches[pair_idx].dst_img_idx = to; |
|
|
|
|
|
|
|
|
|
|
|
size_t dual_pair_idx = to*num_images + from; |
|
|
|
size_t dual_pair_idx = to*num_images + from; |
|
|
|
|
|
|
|
|
|
|
|
pairwise_matches[dual_pair_idx] = pairwise_matches[pair_idx]; |
|
|
|
pairwise_matches[dual_pair_idx] = pairwise_matches[pair_idx]; |
|
|
|
pairwise_matches[dual_pair_idx].src_img_idx = to; |
|
|
|
pairwise_matches[dual_pair_idx].src_img_idx = to; |
|
|
|
pairwise_matches[dual_pair_idx].dst_img_idx = from; |
|
|
|
pairwise_matches[dual_pair_idx].dst_img_idx = from; |
|
|
|
|
|
|
|
|
|
|
|
if (!pairwise_matches[pair_idx].H.empty()) |
|
|
|
if (!pairwise_matches[pair_idx].H.empty()) |
|
|
|
pairwise_matches[dual_pair_idx].H = pairwise_matches[pair_idx].H.inv(); |
|
|
|
pairwise_matches[dual_pair_idx].H = pairwise_matches[pair_idx].H.inv(); |
|
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0; j < pairwise_matches[dual_pair_idx].matches.size(); ++j) |
|
|
|
for (size_t j = 0; j < pairwise_matches[dual_pair_idx].matches.size(); ++j) |
|
|
|
std::swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx, |
|
|
|
std::swap(pairwise_matches[dual_pair_idx].matches[j].queryIdx, |
|
|
|
pairwise_matches[dual_pair_idx].matches[j].trainIdx); |
|
|
|
pairwise_matches[dual_pair_idx].matches[j].trainIdx); |
|
|
|
LOG("."); |
|
|
|
LOG("."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FeaturesMatcher &matcher; |
|
|
|
FeaturesMatcher &matcher; |
|
|
|
const vector<ImageFeatures> &features; |
|
|
|
const vector<ImageFeatures> &features; |
|
|
|
vector<MatchesInfo> &pairwise_matches; |
|
|
|
vector<MatchesInfo> &pairwise_matches; |
|
|
|
vector<pair<int,int> > &near_pairs; |
|
|
|
vector<pair<int,int> > &near_pairs; |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
void operator =(const MatchPairsBody&); |
|
|
|
void operator =(const MatchPairsBody&); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<MatchesInfo> &pairwise_matches) |
|
|
|
void cv::FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<MatchesInfo> &pairwise_matches) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const int num_images = static_cast<int>(features.size()); |
|
|
|
const int num_images = static_cast<int>(features.size()); |
|
|
|
|
|
|
|
|
|
|
@ -408,10 +403,10 @@ namespace |
|
|
|
vector< vector<DMatch> >().swap(pair_matches); |
|
|
|
vector< vector<DMatch> >().swap(pair_matches); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2) |
|
|
|
cv::BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (try_use_gpu && getCudaEnabledDeviceCount() > 0) |
|
|
|
if (try_use_gpu && getCudaEnabledDeviceCount() > 0) |
|
|
|
impl_ = new GpuMatcher(match_conf); |
|
|
|
impl_ = new GpuMatcher(match_conf); |
|
|
@ -424,7 +419,7 @@ BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, |
|
|
|
void cv::BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, |
|
|
|
MatchesInfo &matches_info) |
|
|
|
MatchesInfo &matches_info) |
|
|
|
{ |
|
|
|
{ |
|
|
|
(*impl_)(features1, features2, matches_info); |
|
|
|
(*impl_)(features1, features2, matches_info); |
|
|
@ -502,9 +497,7 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea |
|
|
|
matches_info.H = findHomography(src_points, dst_points, CV_RANSAC); |
|
|
|
matches_info.H = findHomography(src_points, dst_points, CV_RANSAC); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BestOf2NearestMatcher::releaseMemory() |
|
|
|
void cv::BestOf2NearestMatcher::releaseMemory() |
|
|
|
{ |
|
|
|
{ |
|
|
|
impl_->releaseMemory(); |
|
|
|
impl_->releaseMemory(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace cv
|
|
|
|
|
|
|
|