Commit 4401f33e authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

fixed error in gcgraph which led to problems in opencv_stitching GC seam finder,…

fixed error in gcgraph which led to problems in opencv_stitching GC seam finder, added check for duplication in matches (opencv_stitching)
parent 1a0b1d2a
......@@ -97,7 +97,7 @@ template <class TWeight>
void GCGraph<TWeight>::create( unsigned int vtxCount, unsigned int edgeCount )
{
vtcs.reserve( vtxCount );
edges.reserve( edgeCount );
edges.reserve( edgeCount + 2 );
flow = 0;
}
......@@ -118,6 +118,9 @@ void GCGraph<TWeight>::addEdges( int i, int j, TWeight w, TWeight revw )
CV_Assert( w>=0 && revw>=0 );
CV_Assert( i != j );
if( !edges.size() )
edges.resize( 2 );
Edge fromI, toI;
fromI.dst = j;
fromI.next = vtcs[i].first;
......
......@@ -71,7 +71,7 @@ void printUsage()
" --try_gpu (yes|no)\n"
" Try to use GPU. The default value is 'no'. All default values\n"
" are for CPU mode.\n"
"\nMotion Estimation:\n"
"\nMotion Estimation Flags:\n"
" --work_megapix <float>\n"
" Resolution for image registration step. The default is 0.6 Mpx.\n"
" --match_conf <float>\n"
......@@ -83,7 +83,7 @@ void printUsage()
" Bundle adjustment cost function. The default is 'focal_ray'.\n"
" --wave_correct (no|yes)\n"
" Perform wave effect correction. The default is 'yes'.\n"
"\nCompositing:\n"
"\nCompositing Flags:\n"
" --warp (plane|cylindrical|spherical)\n"
" Warp surface type. The default is 'spherical'.\n"
" --seam_megapix <float>\n"
......
......@@ -257,6 +257,16 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
namespace
{
class PairLess
{
public:
bool operator()(const pair<int,int>& l, const pair<int,int>& r) const
{
return l.first < r.first || (l.first == r.first && l.second < r.second);
}
};
typedef set<pair<int,int>,PairLess> MatchesSet;
// These two classes are aimed to find features matches only, not to
// estimate homography
......@@ -289,6 +299,7 @@ namespace
matches_info.matches.clear();
FlannBasedMatcher matcher;
vector< vector<DMatch> > pair_matches;
MatchesSet matches;
// Find 1->2 matches
matcher.knnMatch(features1.descriptors, features2.descriptors, pair_matches, 2);
......@@ -299,7 +310,10 @@ namespace
const DMatch& m0 = pair_matches[i][0];
const DMatch& m1 = pair_matches[i][1];
if (m0.distance < (1.f - match_conf_) * m1.distance)
{
matches_info.matches.push_back(m0);
matches.insert(make_pair(m0.queryIdx, m0.trainIdx));
}
}
// Find 2->1 matches
......@@ -312,6 +326,7 @@ namespace
const DMatch& m0 = pair_matches[i][0];
const DMatch& m1 = pair_matches[i][1];
if (m0.distance < (1.f - match_conf_) * m1.distance)
if (matches.find(make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
matches_info.matches.push_back(DMatch(m0.trainIdx, m0.queryIdx, m0.distance));
}
}
......@@ -324,6 +339,7 @@ namespace
descriptors2_.upload(features2.descriptors);
BruteForceMatcher_GPU< L2<float> > matcher;
vector< vector<DMatch> > pair_matches;
MatchesSet matches;
// Find 1->2 matches
matcher.knnMatch(descriptors1_, descriptors2_, train_idx_, distance_, all_dist_, 2);
......@@ -335,7 +351,10 @@ namespace
const DMatch& m0 = pair_matches[i][0];
const DMatch& m1 = pair_matches[i][1];
if (m0.distance < (1.f - match_conf_) * m1.distance)
{
matches_info.matches.push_back(m0);
matches.insert(make_pair(m0.queryIdx, m0.trainIdx));
}
}
// Find 2->1 matches
......@@ -349,6 +368,7 @@ namespace
const DMatch& m0 = pair_matches[i][0];
const DMatch& m1 = pair_matches[i][1];
if (m0.distance < (1.f - match_conf_) * m1.distance)
if (matches.find(make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
matches_info.matches.push_back(DMatch(m0.trainIdx, m0.queryIdx, m0.distance));
}
}
......
......@@ -49,6 +49,7 @@
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include "opencv2/core/core.hpp"
#include "opencv2/core/internal.hpp"
#include "opencv2/imgproc/imgproc.hpp"
......
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