rewrote matchTemplate in C++; added border awareness to crossCorr (ticket #557)
This commit is contained in:
parent
66d10b1815
commit
9e7b8d5f67
@ -2994,15 +2994,18 @@ void filter2D( const Mat& src, Mat& dst, int ddepth,
|
|||||||
dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
|
dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) );
|
||||||
anchor = normalizeAnchor(anchor, kernel.size());
|
anchor = normalizeAnchor(anchor, kernel.size());
|
||||||
|
|
||||||
if( kernel.cols*kernel.rows >= dft_filter_size /*&&
|
if( kernel.cols*kernel.rows >= dft_filter_size )
|
||||||
kernel.cols <= src.cols && kernel.rows <= src.rows*/ )
|
|
||||||
{
|
{
|
||||||
Mat temp;
|
Mat temp;
|
||||||
if( src.data != dst.data )
|
if( src.data != dst.data )
|
||||||
temp = src;
|
temp = dst;
|
||||||
else
|
else
|
||||||
src.copyTo(temp);
|
temp.create(dst.size(), dst.type());
|
||||||
crossCorr( temp, kernel, dst, anchor, delta, borderType );
|
crossCorr( src, kernel, temp, src.size(),
|
||||||
|
CV_MAKETYPE(ddepth, src.channels()),
|
||||||
|
anchor, delta, borderType );
|
||||||
|
if( temp.data != dst.data )
|
||||||
|
temp.copyTo(dst);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ static inline Point normalizeAnchor( Point anchor, Size ksize )
|
|||||||
|
|
||||||
void preprocess2DKernel( const Mat& kernel, vector<Point>& coords, vector<uchar>& coeffs );
|
void preprocess2DKernel( const Mat& kernel, vector<Point>& coords, vector<uchar>& coeffs );
|
||||||
void crossCorr( const Mat& src, const Mat& templ, Mat& dst,
|
void crossCorr( const Mat& src, const Mat& templ, Mat& dst,
|
||||||
|
Size corrsize, int ctype,
|
||||||
Point anchor=Point(0,0), double delta=0,
|
Point anchor=Point(0,0), double delta=0,
|
||||||
int borderType=BORDER_REFLECT_101 );
|
int borderType=BORDER_REFLECT_101 );
|
||||||
|
|
||||||
@ -124,11 +125,6 @@ void icvSepConvSmall3_32f( float* src, int src_step, float* dst, int dst_step,
|
|||||||
#undef CV_CALC_MAX
|
#undef CV_CALC_MAX
|
||||||
#define CV_CALC_MAX(a, b) if((a) < (b)) (a) = (b)
|
#define CV_CALC_MAX(a, b) if((a) < (b)) (a) = (b)
|
||||||
|
|
||||||
void
|
|
||||||
icvCrossCorr( const CvArr* _img, const CvArr* _templ,
|
|
||||||
CvArr* _corr, CvPoint anchor=cvPoint(0,0),
|
|
||||||
double delta=0, int borderType=IPL_BORDER_REPLICATE);
|
|
||||||
|
|
||||||
CvStatus CV_STDCALL
|
CvStatus CV_STDCALL
|
||||||
icvCopyReplicateBorder_8u( const uchar* src, int srcstep, CvSize srcroi,
|
icvCopyReplicateBorder_8u( const uchar* src, int srcstep, CvSize srcroi,
|
||||||
uchar* dst, int dststep, CvSize dstroi,
|
uchar* dst, int dststep, CvSize dstroi,
|
||||||
|
@ -442,6 +442,7 @@ cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
|
|||||||
if( dststep == 0 )
|
if( dststep == 0 )
|
||||||
dststep = CV_STUB_STEP;
|
dststep = CV_STUB_STEP;
|
||||||
|
|
||||||
|
bordertype &= 15;
|
||||||
if( bordertype == IPL_BORDER_REPLICATE )
|
if( bordertype == IPL_BORDER_REPLICATE )
|
||||||
{
|
{
|
||||||
icvCopyReplicateBorder_8u( src->data.ptr, srcstep, srcsize,
|
icvCopyReplicateBorder_8u( src->data.ptr, srcstep, srcsize,
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
using namespace cv; // all the new API is put into "cv" namespace. Export its content
|
using namespace cv; // all the new API is put into "cv" namespace. Export its content
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
// enable/disable use of mixed API in the code below.
|
// enable/disable use of mixed API in the code below.
|
||||||
#define DEMO_MIXED_API_USE 1
|
#define DEMO_MIXED_API_USE 1
|
||||||
|
|
||||||
@ -108,3 +110,30 @@ int main( int argc, char** argv )
|
|||||||
// all the memory will automatically be released by Vector<>, Mat and Ptr<> destructors.
|
// all the memory will automatically be released by Vector<>, Mat and Ptr<> destructors.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
Mat im(160, 160, CV_32F);
|
||||||
|
randu(im, Scalar(0.0), Scalar(1.0));
|
||||||
|
Mat dd = Mat::zeros(17,1,CV_32F);
|
||||||
|
Mat lp = Mat::zeros(17,1,CV_32F);
|
||||||
|
dd.at<float>(0) = 0.5;
|
||||||
|
dd.at<float>(16) = -0.5;
|
||||||
|
lp.at<float>(0) = 0.5;
|
||||||
|
lp.at<float>(16) = 0.5;
|
||||||
|
int p = 16;
|
||||||
|
Mat H = dd*lp.t();
|
||||||
|
Mat imcrop(im, Rect(17, 17, im.cols-2*p, im.rows-2*p));
|
||||||
|
Mat out1, out2;
|
||||||
|
filter2D(imcrop, out1, CV_32F, H, Point(-1,-1));
|
||||||
|
sepFilter2D(imcrop, out2, CV_32F, lp, dd, Point(-1,-1));
|
||||||
|
Mat temp;
|
||||||
|
out1.convertTo(temp, CV_16U, 65535.0, 32768.0);
|
||||||
|
imshow("filtered1.png", temp);
|
||||||
|
out2.convertTo(temp, CV_16U, 65535.0, 32768.0);
|
||||||
|
imshow("filtered2.png", temp);
|
||||||
|
waitKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user