Skip to content

Commit

Permalink
Merge pull request opencv#3116 from shubhra:master
Browse files Browse the repository at this point in the history
  • Loading branch information
vpisarev committed Aug 22, 2014
2 parents 0eb1c7e + 7b2a1d1 commit 887a950
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,11 @@ findHomography
------------------
Finds a perspective transformation between two planes.

.. ocv:function:: Mat findHomography( InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray() )
.. ocv:function:: Mat findHomography( InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray(), const int maxIters = 2000, const double confidence = 0.995)
.. ocv:pyfunction:: cv2.findHomography(srcPoints, dstPoints[, method[, ransacReprojThreshold[, mask]]]) -> retval, mask
.. ocv:cfunction:: int cvFindHomography( const CvMat* src_points, const CvMat* dst_points, CvMat* homography, int method=0, double ransacReprojThreshold=3, CvMat* mask=0 )
.. ocv:cfunction:: int cvFindHomography( const CvMat* src_points, const CvMat* dst_points, CvMat* homography, int method=0, double ransacReprojThreshold=3, CvMat* mask=0, int maxIters = 2000, double confidence = 0.995)
:param srcPoints: Coordinates of the points in the original plane, a matrix of the type ``CV_32FC2`` or ``vector<Point2f>`` .

Expand All @@ -871,6 +871,10 @@ Finds a perspective transformation between two planes.

:param mask: Optional output mask set by a robust method ( ``RANSAC`` or ``LMEDS`` ). Note that the input mask values are ignored.

:param maxIters: The maximum number of RANSAC iterations, 2000 is the maximum it can be.

:param confidence: Confidence level, between 0 and 1.

The functions find and return the perspective transformation :math:`H` between the source and the destination planes:

.. math::
Expand Down
3 changes: 2 additions & 1 deletion modules/calib3d/include/opencv2/calib3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobi
//! computes the best-fit perspective transformation mapping srcPoints to dstPoints.
CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
int method = 0, double ransacReprojThreshold = 3,
OutputArray mask=noArray());
OutputArray mask=noArray(), const int maxIters = 2000,
const double confidence = 0.995);

//! variant of findHomography for backward compatibility
CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints,
Expand Down
4 changes: 3 additions & 1 deletion modules/calib3d/include/opencv2/calib3d/calib3d_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ CVAPI(int) cvFindHomography( const CvMat* src_points,
CvMat* homography,
int method CV_DEFAULT(0),
double ransacReprojThreshold CV_DEFAULT(3),
CvMat* mask CV_DEFAULT(0));
CvMat* mask CV_DEFAULT(0),
int maxIters CV_DEFAULT(2000),
double confidence CV_DEFAULT(0.995));

/* Computes RQ decomposition for 3x3 matrices */
CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
Expand Down
16 changes: 14 additions & 2 deletions modules/calib3d/src/compat_ptsetreg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ CV_IMPL int cvRANSACUpdateNumIters( double p, double ep, int modelPoints, int ma


CV_IMPL int cvFindHomography( const CvMat* _src, const CvMat* _dst, CvMat* __H, int method,
double ransacReprojThreshold, CvMat* _mask )
double ransacReprojThreshold, CvMat* _mask, int maxIters,
double confidence)
{
cv::Mat src = cv::cvarrToMat(_src), dst = cv::cvarrToMat(_dst);

Expand All @@ -308,9 +309,20 @@ CV_IMPL int cvFindHomography( const CvMat* _src, const CvMat* _dst, CvMat* __H,
if( dst.channels() == 1 && (dst.rows == 2 || dst.rows == 3) && dst.cols > 3 )
cv::transpose(dst, dst);

if ( maxIters < 0 )
maxIters = 0;
if ( maxIters > 2000 )
maxIters = 2000;

if ( confidence < 0 )
confidence = 0;
if ( confidence > 1 )
confidence = 1;

const cv::Mat H = cv::cvarrToMat(__H), mask = cv::cvarrToMat(_mask);
cv::Mat H0 = cv::findHomography(src, dst, method, ransacReprojThreshold,
_mask ? cv::_OutputArray(mask) : cv::_OutputArray());
_mask ? cv::_OutputArray(mask) : cv::_OutputArray(), maxIters,
confidence);

if( H0.empty() )
{
Expand Down
5 changes: 2 additions & 3 deletions modules/calib3d/src/fundam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,9 @@ class HomographyRefineCallback : public LMSolver::Callback


cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
int method, double ransacReprojThreshold, OutputArray _mask )
int method, double ransacReprojThreshold, OutputArray _mask,
const int maxIters, const double confidence)
{
const double confidence = 0.995;
const int maxIters = 2000;
const double defaultRANSACReprojThreshold = 3;
bool result = false;

Expand Down

0 comments on commit 887a950

Please sign in to comment.