{
static void
-getRTMatrix( const Point2f* a, const Point2f* b,
+getRTMatrix( const std::vector<Point2f> a, const std::vector<Point2f> b,
int count, Mat& M, bool fullAffine )
{
CV_Assert( M.isContinuous() );
cv::Mat cv::estimateRigidTransform( InputArray src1, InputArray src2, bool fullAffine )
{
+ return estimateRigidTransform(src1, src2, fullAffine, 500, 0.5, 3);
+}
+
+cv::Mat cv::estimateRigidTransform( InputArray src1, InputArray src2, bool fullAffine, int ransacMaxIters, double ransacGoodRatio,
+ const int ransacSize0)
+{
CV_INSTRUMENT_REGION()
Mat M(2, 3, CV_64F), A = src1.getMat(), B = src2.getMat();
const int COUNT = 15;
const int WIDTH = 160, HEIGHT = 120;
- const int RANSAC_MAX_ITERS = 500;
- const int RANSAC_SIZE0 = 3;
- const double RANSAC_GOOD_RATIO = 0.5;
std::vector<Point2f> pA, pB;
std::vector<int> good_idx;
RNG rng((uint64)-1);
int good_count = 0;
+ if( ransacSize0 < 3 )
+ CV_Error( Error::StsBadArg, "ransacSize0 should have value bigger than 2.");
+
+ if( ransacGoodRatio > 1 || ransacGoodRatio < 0)
+ CV_Error( Error::StsBadArg, "ransacGoodRatio should have value between 0 and 1");
+
if( A.size() != B.size() )
CV_Error( Error::StsUnmatchedSizes, "Both input images must have the same size" );
good_idx.resize(count);
- if( count < RANSAC_SIZE0 )
+ if( count < ransacSize0 )
return Mat();
Rect brect = boundingRect(pB);
+ std::vector<Point2f> a(ransacSize0);
+ std::vector<Point2f> b(ransacSize0);
+
// RANSAC stuff:
// 1. find the consensus
- for( k = 0; k < RANSAC_MAX_ITERS; k++ )
+ for( k = 0; k < ransacMaxIters; k++ )
{
- int idx[RANSAC_SIZE0];
- Point2f a[RANSAC_SIZE0];
- Point2f b[RANSAC_SIZE0];
-
- // choose random 3 non-coplanar points from A & B
- for( i = 0; i < RANSAC_SIZE0; i++ )
+ std::vector<int> idx(ransacSize0);
+ // choose random 3 non-complanar points from A & B
+ for( i = 0; i < ransacSize0; i++ )
{
- for( k1 = 0; k1 < RANSAC_MAX_ITERS; k1++ )
+ for( k1 = 0; k1 < ransacMaxIters; k1++ )
{
idx[i] = rng.uniform(0, count);
if( j < i )
continue;
- if( i+1 == RANSAC_SIZE0 )
+ if( i+1 == ransacSize0 )
{
// additional check for non-complanar vectors
a[0] = pA[idx[0]];
break;
}
- if( k1 >= RANSAC_MAX_ITERS )
+ if( k1 >= ransacMaxIters )
break;
}
- if( i < RANSAC_SIZE0 )
+ if( i < ransacSize0 )
continue;
// estimate the transformation using 3 points
good_idx[good_count++] = i;
}
- if( good_count >= count*RANSAC_GOOD_RATIO )
+ if( good_count >= count*ransacGoodRatio )
break;
}
- if( k >= RANSAC_MAX_ITERS )
+ if( k >= ransacMaxIters )
return Mat();
if( good_count < count )
}
}
- getRTMatrix( &pA[0], &pB[0], good_count, M, fullAffine );
+ getRTMatrix( pA, pB, good_count, M, fullAffine );
M.at<double>(0, 2) /= scale;
M.at<double>(1, 2) /= scale;