Path: blob/master/modules/imgproc/perf/perf_matchTemplate.cpp
16339 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3#include "perf_precomp.hpp"45namespace opencv_test {67CV_ENUM(MethodType, TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED)89typedef tuple<Size, Size, MethodType> ImgSize_TmplSize_Method_t;10typedef perf::TestBaseWithParam<ImgSize_TmplSize_Method_t> ImgSize_TmplSize_Method;1112PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateSmall,13testing::Combine(14testing::Values(szSmall128, cv::Size(320, 240),15cv::Size(640, 480), cv::Size(800, 600),16cv::Size(1024, 768), cv::Size(1280, 1024)),17testing::Values(cv::Size(12, 12), cv::Size(28, 9),18cv::Size(8, 30), cv::Size(16, 16)),19MethodType::all()20)21)22{23Size imgSz = get<0>(GetParam());24Size tmplSz = get<1>(GetParam());25int method = get<2>(GetParam());2627Mat img(imgSz, CV_8UC1);28Mat tmpl(tmplSz, CV_8UC1);29Mat result(imgSz - tmplSz + Size(1,1), CV_32F);3031declare32.in(img, WARMUP_RNG)33.in(tmpl, WARMUP_RNG)34.out(result)35.time(30);3637TEST_CYCLE() matchTemplate(img, tmpl, result, method);3839bool isNormed =40method == TM_CCORR_NORMED ||41method == TM_SQDIFF_NORMED ||42method == TM_CCOEFF_NORMED;43double eps = isNormed ? 1e-544: 255 * 255 * tmpl.total() * 1e-6;4546SANITY_CHECK(result, eps);47}4849PERF_TEST_P(ImgSize_TmplSize_Method, matchTemplateBig,50testing::Combine(51testing::Values(cv::Size(1280, 1024)),52testing::Values(cv::Size(1260, 1000), cv::Size(1261, 1013)),53MethodType::all()54)55)56{57Size imgSz = get<0>(GetParam());58Size tmplSz = get<1>(GetParam());59int method = get<2>(GetParam());6061Mat img(imgSz, CV_8UC1);62Mat tmpl(tmplSz, CV_8UC1);63Mat result(imgSz - tmplSz + Size(1,1), CV_32F);6465declare66.in(img, WARMUP_RNG)67.in(tmpl, WARMUP_RNG)68.out(result)69.time(30);7071TEST_CYCLE() matchTemplate(img, tmpl, result, method);7273bool isNormed =74method == TM_CCORR_NORMED ||75method == TM_SQDIFF_NORMED ||76method == TM_CCOEFF_NORMED;77double eps = isNormed ? 1e-678: 255.0 * 255.0 * (double)tmpl.total() * 1e-6;7980SANITY_CHECK(result, eps);81}8283} // namespace848586