From 6dbf13d7b5e017a8b16cf5f12a38000896e64583 Mon Sep 17 00:00:00 2001 From: ASUS Date: Thu, 12 Feb 2015 21:22:52 -0500 Subject: [PATCH] saveBestModel() is modified. accuracy test is passed. --- modules/calib3d/src/fundam.cpp | 13 +++++---- modules/calib3d/src/rhorefc.cpp | 47 +++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index 1366e9baa7..2f6058c747 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -399,16 +399,18 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2, { tempMask = Mat::ones(npoints, 1, CV_8U); result = cb->runKernel(src, dst, H) > 0; - } - else if( method == RANSAC ) + } + + else if( method == RANSAC) result = createRANSACPointSetRegistrator(cb, 4, ransacReprojThreshold, confidence, maxIters)->run(src, dst, H, tempMask); else if( method == LMEDS ) result = createLMeDSPointSetRegistrator(cb, 4, confidence, maxIters)->run(src, dst, H, tempMask); - else if( method == RHO ){ + else if( method == RHO ) result = createAndRunRHORegistrator(confidence, maxIters, ransacReprojThreshold, npoints, src, dst, H, tempMask); - }else + else CV_Error(Error::StsBadArg, "Unknown estimation method"); + if( result && npoints > 4 && method != RHO) { compressPoints( src.ptr(), tempMask.ptr(), 1, npoints ); @@ -419,8 +421,9 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2, Mat dst1 = dst.rowRange(0, npoints); src = src1; dst = dst1; - if( method == RANSAC || method == LMEDS ) + if( method == RANSAC || method == LMEDS) cb->runKernel( src, dst, H ); + Mat H8(8, 1, CV_64F, H.ptr()); createLMSolver(makePtr(src, dst), 10)->run(H8); } diff --git a/modules/calib3d/src/rhorefc.cpp b/modules/calib3d/src/rhorefc.cpp index 3cc9a8a1c3..976f8d341d 100644 --- a/modules/calib3d/src/rhorefc.cpp +++ b/modules/calib3d/src/rhorefc.cpp @@ -55,7 +55,6 @@ #include "rhorefc.h" - /* Defines */ #define MEM_ALIGN 32 #define HSIZE (3*3*sizeof(float)) @@ -383,7 +382,7 @@ unsigned rhoRefC(RHO_HEST_REFC* restrict p, /* Homography estimation conte * PROSAC Loop */ - for(p->ctrl.i=0; p->ctrl.i < p->arg.maxI; p->ctrl.i++){ + for(p->ctrl.i=0; p->ctrl.i < p->arg.maxI || p->ctrl.i<100; p->ctrl.i++){ sacHypothesize(p) && sacVerify(p); } @@ -861,7 +860,28 @@ static inline int sacIsSampleDegenerate(RHO_HEST_REFC* p){ */ static inline void sacGenerateModel(RHO_HEST_REFC* p){ +#if 1 hFuncRefC(p->curr.pkdPts, p->curr.H); +#else + int mm = 4; + cv::Mat _H(3,3,CV_32FC1); + std::vector _srcPoints(mm,cv::Point2f()); + std::vector _dstPoints(mm,cv::Point2f()); + for (int i=0 ; i< mm ; i++){ + cv::Point2f tempPoint2f(p->curr.pkdPts[2*i], p->curr.pkdPts[2*i+1]); + _srcPoints[i] = tempPoint2f; + tempPoint2f=cv::Point2f((float)p->curr.pkdPts[2*i+8],(float) p->curr.pkdPts[2*i+9]); + _dstPoints[i] = tempPoint2f; + } + + _H = cv::findHomography(_srcPoints, _dstPoints,0,3); + double* data = (double*) _H.data; + + p->curr.H[0]=data[0]; p->curr.H[1]=data[1]; p->curr.H[2]=data[2]; + p->curr.H[3]=data[3]; p->curr.H[4]=data[4]; p->curr.H[5]=data[5]; + p->curr.H[6]=data[6]; p->curr.H[7]=data[7]; p->curr.H[8]=1.0; + +#endif } /** @@ -1074,17 +1094,22 @@ static inline int sacIsBestModelGoodEnough(RHO_HEST_REFC* p){ */ static inline void sacSaveBestModel(RHO_HEST_REFC* p){ - float* H = p->curr.H; - char* inl = p->curr.inl; - unsigned numInl = p->curr.numInl; - p->curr.H = p->best.H; - p->curr.inl = p->best.inl; - p->curr.numInl = p->best.numInl; + memcpy(p->best.H, p->curr.H, HSIZE); + memcpy(p->best.inl, p->curr.inl, p->arg.N); + p->best.numInl = p->curr.numInl; - p->best.H = H; - p->best.inl = inl; - p->best.numInl = numInl; +// float* H = p->curr.H; +// char* inl = p->curr.inl; +// unsigned numInl = p->curr.numInl; + +// p->curr.H = p->best.H; +// p->curr.inl = p->best.inl; +// p->curr.numInl = p->best.numInl; + +// p->best.H = H; +// p->best.inl = inl; +// p->best.numInl = numInl; } /**