@ -309,16 +309,48 @@ static void update_warping_matrix_ECC (Mat& map_matrix, const Mat& update, const
}
}
/** Function that computes enhanced corelation coefficient from Georgios et.al. 2008
* See https : //github.com/opencv/opencv/issues/12432
*/
double cv : : computeECC ( InputArray templateImage , InputArray inputImage , InputArray inputMask )
{
CV_Assert ( ! templateImage . empty ( ) ) ;
CV_Assert ( ! inputImage . empty ( ) ) ;
if ( ! ( templateImage . type ( ) = = inputImage . type ( ) ) )
CV_Error ( Error : : StsUnmatchedFormats , " Both input images must have the same data type " ) ;
Scalar meanTemplate , sdTemplate ;
int active_pixels = inputMask . empty ( ) ? templateImage . size ( ) . area ( ) : countNonZero ( inputMask ) ;
meanStdDev ( templateImage , meanTemplate , sdTemplate , inputMask ) ;
Mat templateImage_zeromean = Mat : : zeros ( templateImage . size ( ) , templateImage . type ( ) ) ;
subtract ( templateImage , meanTemplate , templateImage_zeromean , inputMask ) ;
double templateImagenorm = std : : sqrt ( active_pixels * sdTemplate . val [ 0 ] * sdTemplate . val [ 0 ] ) ;
Scalar meanInput , sdInput ;
Mat inputImage_zeromean = Mat : : zeros ( inputImage . size ( ) , inputImage . type ( ) ) ;
meanStdDev ( inputImage , meanInput , sdInput , inputMask ) ;
subtract ( inputImage , meanInput , inputImage_zeromean , inputMask ) ;
double inputImagenorm = std : : sqrt ( active_pixels * sdInput . val [ 0 ] * sdInput . val [ 0 ] ) ;
return templateImage_zeromean . dot ( inputImage_zeromean ) / ( templateImagenorm * inputImagenorm ) ;
}
double cv : : findTransformECC ( InputArray templateImage ,
double cv : : findTransformECC ( InputArray templateImage ,
InputArray inputImage ,
InputArray inputImage ,
InputOutputArray warpMatrix ,
InputOutputArray warpMatrix ,
int motionType ,
int motionType ,
TermCriteria criteria ,
TermCriteria criteria ,
InputArray inputMask )
InputArray inputMask ,
int gaussFiltSize )
{
{
Mat src = templateImage . getMat ( ) ; //template iamge
Mat src = templateImage . getMat ( ) ; //template ima ge
Mat dst = inputImage . getMat ( ) ; //input image (to be warped)
Mat dst = inputImage . getMat ( ) ; //input image (to be warped)
Mat map = warpMatrix . getMat ( ) ; //warp (transformation)
Mat map = warpMatrix . getMat ( ) ; //warp (transformation)
@ -416,11 +448,11 @@ double cv::findTransformECC(InputArray templateImage,
//gaussian filtering is optional
//gaussian filtering is optional
src . convertTo ( templateFloat , templateFloat . type ( ) ) ;
src . convertTo ( templateFloat , templateFloat . type ( ) ) ;
GaussianBlur ( templateFloat , templateFloat , Size ( 5 , 5 ) , 0 , 0 ) ;
GaussianBlur ( templateFloat , templateFloat , Size ( gaussFiltSize , gaussFiltSize ) , 0 , 0 ) ;
Mat preMaskFloat ;
Mat preMaskFloat ;
preMask . convertTo ( preMaskFloat , CV_32F ) ;
preMask . convertTo ( preMaskFloat , CV_32F ) ;
GaussianBlur ( preMaskFloat , preMaskFloat , Size ( 5 , 5 ) , 0 , 0 ) ;
GaussianBlur ( preMaskFloat , preMaskFloat , Size ( gaussFiltSize , gaussFiltSize ) , 0 , 0 ) ;
// Change threshold.
// Change threshold.
preMaskFloat * = ( 0.5 / 0.95 ) ;
preMaskFloat * = ( 0.5 / 0.95 ) ;
// Rounding conversion.
// Rounding conversion.
@ -428,7 +460,7 @@ double cv::findTransformECC(InputArray templateImage,
preMask . convertTo ( preMaskFloat , preMaskFloat . type ( ) ) ;
preMask . convertTo ( preMaskFloat , preMaskFloat . type ( ) ) ;
dst . convertTo ( imageFloat , imageFloat . type ( ) ) ;
dst . convertTo ( imageFloat , imageFloat . type ( ) ) ;
GaussianBlur ( imageFloat , imageFloat , Size ( 5 , 5 ) , 0 , 0 ) ;
GaussianBlur ( imageFloat , imageFloat , Size ( gaussFiltSize , gaussFiltSize ) , 0 , 0 ) ;
// needed matrices for gradients and warped gradients
// needed matrices for gradients and warped gradients
Mat gradientX = Mat : : zeros ( hd , wd , CV_32FC1 ) ;
Mat gradientX = Mat : : zeros ( hd , wd , CV_32FC1 ) ;
@ -557,5 +589,13 @@ double cv::findTransformECC(InputArray templateImage,
return rho ;
return rho ;
}
}
double cv : : findTransformECC ( InputArray templateImage , InputArray inputImage ,
InputOutputArray warpMatrix , int motionType ,
TermCriteria criteria ,
InputArray inputMask )
{
// Use default value of 5 for gaussFiltSize to maintain backward compatibility.
return findTransformECC ( templateImage , inputImage , warpMatrix , motionType , criteria , inputMask , 5 ) ;
}
/* End of file. */
/* End of file. */