This source file includes following definitions.
- CV_ENUM
- OCL_TEST_P
#include "../test_precomp.hpp"
#include "opencv2/ts/ocl_test.hpp"
#include "iostream"
#include "fstream"
#ifdef HAVE_OPENCL
namespace cvtest {
namespace ocl {
CV_ENUM(MatchTemplType, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCOEFF, CV_TM_CCOEFF_NORMED)
PARAM_TEST_CASE(MatchTemplate, MatDepth, Channels, MatchTemplType, bool)
{
int type;
int depth;
int method;
bool use_roi;
TEST_DECLARE_INPUT_PARAMETER(image);
TEST_DECLARE_INPUT_PARAMETER(templ);
TEST_DECLARE_OUTPUT_PARAMETER(result);
virtual void SetUp()
{
type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1));
depth = GET_PARAM(0);
method = GET_PARAM(2);
use_roi = GET_PARAM(3);
}
virtual void generateTestData()
{
Size image_roiSize = randomSize(2, 100);
Size templ_roiSize = Size(randomInt(1, image_roiSize.width), randomInt(1, image_roiSize.height));
Size result_roiSize = Size(image_roiSize.width - templ_roiSize.width + 1,
image_roiSize.height - templ_roiSize.height + 1);
const double upValue = 256;
Border imageBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
randomSubMat(image, image_roi, image_roiSize, imageBorder, type, -upValue, upValue);
Border templBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
randomSubMat(templ, templ_roi, templ_roiSize, templBorder, type, -upValue, upValue);
Border resultBorder = randomBorder(0, use_roi ? MAX_VALUE : 0);
randomSubMat(result, result_roi, result_roiSize, resultBorder, CV_32FC1, -upValue, upValue);
UMAT_UPLOAD_INPUT_PARAMETER(image);
UMAT_UPLOAD_INPUT_PARAMETER(templ);
UMAT_UPLOAD_OUTPUT_PARAMETER(result);
}
void Near()
{
bool isNormed =
method == TM_CCORR_NORMED ||
method == TM_SQDIFF_NORMED ||
method == TM_CCOEFF_NORMED;
if (isNormed)
OCL_EXPECT_MATS_NEAR(result, 3e-2);
else
OCL_EXPECT_MATS_NEAR_RELATIVE_SPARSE(result, 1.5e-2);
}
};
OCL_TEST_P(MatchTemplate, Mat)
{
for (int j = 0; j < test_loop_times; j++)
{
generateTestData();
OCL_OFF(cv::matchTemplate(image_roi, templ_roi, result_roi, method));
OCL_ON(cv::matchTemplate(uimage_roi, utempl_roi, uresult_roi, method));
Near();
}
}
OCL_INSTANTIATE_TEST_CASE_P(ImageProc, MatchTemplate, Combine(
Values(CV_8U, CV_32F),
Values(1, 2, 3, 4),
MatchTemplType::all(),
Bool())
);
} }
#endif