Commit de56163f authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored gpu::matchTemplate (converted it into Algorithm)

parent 1fcc8074
......@@ -424,20 +424,24 @@ CV_EXPORTS void meanShiftSegmentation(InputArray src, OutputArray dst, int sp, i
/////////////////////////// Match Template ////////////////////////////
struct CV_EXPORTS MatchTemplateBuf
//! computes the proximity map for the raster template and the image where the template is searched for
class CV_EXPORTS TemplateMatching : public Algorithm
{
Size user_block_size;
GpuMat imagef, templf;
std::vector<GpuMat> images;
std::vector<GpuMat> image_sums;
std::vector<GpuMat> image_sqsums;
public:
virtual void match(InputArray image, InputArray templ, OutputArray result, Stream& stream = Stream::Null()) = 0;
};
//! computes the proximity map for the raster template and the image where the template is searched for
CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, Stream &stream = Stream::Null());
CV_EXPORTS Ptr<TemplateMatching> createTemplateMatching(int srcType, int method, Size user_block_size = Size());
//! computes the proximity map for the raster template and the image where the template is searched for
CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, MatchTemplateBuf &buf, Stream& stream = Stream::Null());
// obsolete
__OPENCV_GPUIMGPROC_DEPR_BEFORE__ void matchTemplate(InputArray image, InputArray templ, OutputArray result,
int method, Stream& stream = Stream::Null()) __OPENCV_GPUIMGPROC_DEPR_AFTER__;
inline void matchTemplate(InputArray image, InputArray templ, OutputArray result, int method, Stream& stream)
{
gpu::createTemplateMatching(image.type(), method)->match(image, templ, result, stream);
}
////////////////////////// Bilateral Filter ///////////////////////////
......
......@@ -76,7 +76,9 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, MatchTemplate8U,
const cv::gpu::GpuMat d_templ(templ);
cv::gpu::GpuMat dst;
TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method);
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(image.type(), method);
TEST_CYCLE() alg->match(d_image, d_templ, dst);
GPU_SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
}
......@@ -116,7 +118,9 @@ PERF_TEST_P(Sz_TemplateSz_Cn_Method, MatchTemplate32F,
const cv::gpu::GpuMat d_templ(templ);
cv::gpu::GpuMat dst;
TEST_CYCLE() cv::gpu::matchTemplate(d_image, d_templ, dst, method);
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(image.type(), method);
TEST_CYCLE() alg->match(d_image, d_templ, dst);
GPU_SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
}
......
This diff is collapsed.
......@@ -82,8 +82,10 @@ GPU_TEST_P(MatchTemplate8U, Accuracy)
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_8U, cn));
cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_8U, cn));
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(image.type(), method);
cv::gpu::GpuMat dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(templ), dst, method);
alg->match(loadMat(image), loadMat(templ), dst);
cv::Mat dst_gold;
cv::matchTemplate(image, templ, dst_gold, method);
......@@ -128,8 +130,10 @@ GPU_TEST_P(MatchTemplate32F, Regression)
cv::Mat image = randomMat(size, CV_MAKETYPE(CV_32F, cn));
cv::Mat templ = randomMat(templ_size, CV_MAKETYPE(CV_32F, cn));
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(image.type(), method);
cv::gpu::GpuMat dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(templ), dst, method);
alg->match(loadMat(image), loadMat(templ), dst);
cv::Mat dst_gold;
cv::matchTemplate(image, templ, dst_gold, method);
......@@ -169,8 +173,10 @@ GPU_TEST_P(MatchTemplateBlackSource, Accuracy)
cv::Mat pattern = readImage("matchtemplate/cat.png");
ASSERT_FALSE(pattern.empty());
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(image.type(), method);
cv::gpu::GpuMat d_dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(pattern), d_dst, method);
alg->match(loadMat(image), loadMat(pattern), d_dst);
cv::Mat dst(d_dst);
......@@ -214,8 +220,10 @@ GPU_TEST_P(MatchTemplate_CCOEF_NORMED, Accuracy)
cv::Mat pattern = readImage(patternName);
ASSERT_FALSE(pattern.empty());
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(image.type(), cv::TM_CCOEFF_NORMED);
cv::gpu::GpuMat d_dst;
cv::gpu::matchTemplate(loadMat(image), loadMat(pattern), d_dst, cv::TM_CCOEFF_NORMED);
alg->match(loadMat(image), loadMat(pattern), d_dst);
cv::Mat dst(d_dst);
......@@ -263,8 +271,10 @@ GPU_TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF_NORMED)
cv::Mat templ = readImage("matchtemplate/template.png");
ASSERT_FALSE(templ.empty());
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(scene.type(), cv::TM_SQDIFF_NORMED);
cv::gpu::GpuMat d_result;
cv::gpu::matchTemplate(loadMat(scene), loadMat(templ), d_result, cv::TM_SQDIFF_NORMED);
alg->match(loadMat(scene), loadMat(templ), d_result);
cv::Mat result(d_result);
......@@ -286,8 +296,10 @@ GPU_TEST_P(MatchTemplate_CanFindBigTemplate, SQDIFF)
cv::Mat templ = readImage("matchtemplate/template.png");
ASSERT_FALSE(templ.empty());
cv::Ptr<cv::gpu::TemplateMatching> alg = cv::gpu::createTemplateMatching(scene.type(), cv::TM_SQDIFF);
cv::gpu::GpuMat d_result;
cv::gpu::matchTemplate(loadMat(scene), loadMat(templ), d_result, cv::TM_SQDIFF);
alg->match(loadMat(scene), loadMat(templ), d_result);
cv::Mat result(d_result);
......
......@@ -17,24 +17,16 @@
using namespace std;
using namespace cv;
static void InitMatchTemplate()
{
Mat src; gen(src, 500, 500, CV_32F, 0, 1);
Mat templ; gen(templ, 500, 500, CV_32F, 0, 1);
gpu::GpuMat d_src(src), d_templ(templ), d_dst;
gpu::matchTemplate(d_src, d_templ, d_dst, TM_CCORR);
}
TEST(matchTemplate)
{
InitMatchTemplate();
Mat src, templ, dst;
gen(src, 3000, 3000, CV_32F, 0, 1);
gpu::GpuMat d_src(src), d_templ, d_dst;
Ptr<gpu::TemplateMatching> alg = gpu::createTemplateMatching(src.type(), TM_CCORR);
for (int templ_size = 5; templ_size < 200; templ_size *= 5)
{
SUBTEST << src.cols << 'x' << src.rows << ", 32FC1" << ", templ " << templ_size << 'x' << templ_size << ", CCORR";
......@@ -47,10 +39,10 @@ TEST(matchTemplate)
CPU_OFF;
d_templ.upload(templ);
gpu::matchTemplate(d_src, d_templ, d_dst, TM_CCORR);
alg->match(d_src, d_templ, d_dst);
GPU_ON;
gpu::matchTemplate(d_src, d_templ, d_dst, TM_CCORR);
alg->match(d_src, d_templ, d_dst);
GPU_OFF;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment