Exemple #1
0
void GetHomographyInliers( MatchArray& aryInlier,
						  const MatchArray& aryMatch,
						  const CFeatureArray& set1,
						  const CFeatureArray& set2,
						  const CHomography& h**o,
						  float tol )
{
	float SQR_TOL = tol*tol;

	aryInlier.resize( aryMatch.size() );

	int k=0;
	for( int i=0; i<aryMatch.size(); ++i )
	{
		const CFeature* ft1 = set1[ aryMatch[i].first ];
		const CFeature* ft2 = set2[ aryMatch[i].second ];

		CvPoint2D64f pt = h**o * cvPoint2D64f( ft1->x, ft1->y );

		double dx = pt.x -ft2->x;
		double dy = pt.y -ft2->y;

		if( dx*dx +dy*dy < SQR_TOL ) // a homography inlier
			aryInlier[k++] = aryMatch[i];	
	}

	aryInlier.resize(k);
}
void MatchSiftFeatures( MatchArray& aryMatch, const CFeatureArray& set1, const CFeatureArray& set2 )
{
	aryMatch.resize( set1.size() );
	int num = 0;

	// for each feature in set1
	for( int i=0; i<(int)set1.size(); ++i )
	{
		if( i%100 == 0 )
			printf( "%d / %d\n", i, set1.size() );
		//
		const CSiftFeature* ft1 = dynamic_cast< const CSiftFeature* >( set1[i] );
		
		int j = FindMatch( ft1, set2 );
		int k = FindMatch( set2[j], set1 );	

		bool bQualMatch = false;
		
		if( i==k )
			bQualMatch = true;
		
		// TODO: Find the best match for ft1 in set2.
		//       The quality of a match can be evaluated. We only 
		//       collect matches of good qualities.
		
		if( bQualMatch )
			aryMatch[ num++ ] = make_pair( i, j );
	}

	aryMatch.resize( num );
}
// -------------------------------------------------------------------
bool
PosixRegEx::execute(MatchArray &sub, const String &str,
               size_t index, size_t count, int eflags)
{
	if( !compiled)
	{
		BLOCXX_THROW(RegExCompileException,
			"Regular expression is not compiled");
	}

	if( index > str.length())
	{
		BLOCXX_THROW(OutOfBoundsException,
			Format("String index out of bounds ("
			       "length = %1, index = %2).",
			       str.length(), index
			).c_str());
	}

	if( count == 0)
	{
		count = m_regex.re_nsub + 1;
	}
	AutoPtrVec<regmatch_t> rsub(new regmatch_t[count]);
	rsub[0].rm_so = -1;
	rsub[0].rm_eo = -1;

	sub.clear();
	m_ecode = ::regexec(&m_regex, str.c_str() + index,
	                    count, rsub.get(), eflags);
	if( m_ecode == REG_NOERROR)
	{
		m_error.erase();
		if( m_flags & REG_NOSUB)
		{
			return true;
		}

		sub.resize(count);
		for(size_t n = 0; n < count; n++)
		{
			if( rsub[n].rm_so < 0 || rsub[n].rm_eo < 0)
			{
				sub[n] = rsub[n];
			}
			else
			{
				rsub[n].rm_so += index;
				rsub[n].rm_eo += index;
				sub[n] = rsub[n];
			}
		}
		return true;
	}
	else
	{
		m_error = getError(&m_regex, m_ecode);
		return false;
	}
}