1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"
namespace opencv_test { namespace {
TEST(ximgproc_matchcolortemplate,test_QFFT)
{
String openCVExtraDir = cvtest::TS::ptr()->get_data_path();
String dataPath = openCVExtraDir;
#ifdef GENERATE_TESTDATA
FileStorage fs;
dataPath += "cv/ximgproc/sources/07.png";
Mat imgTest = imread(dataPath, IMREAD_COLOR);
resize(imgTest, imgTest, Size(), 0.0625, 0.0625);
Mat qimgTest, qdftimgTest;
ximgproc::createQuaternionImage(imgTest, qimgTest);
ximgproc::qdft(qimgTest, qdftimgTest, 0, true);
fs.open(openCVExtraDir + "cv/ximgproc/qdftData.yml.gz", FileStorage::WRITE);
fs << "image" << imgTest;
fs << "qdftleft" << qdftimgTest;
ximgproc::qdft(qimgTest, qdftimgTest, 0, false);
fs << "qdftright" << qdftimgTest;
ximgproc::qdft(qimgTest, qdftimgTest, DFT_INVERSE, true);
fs << "qidftleft" << qdftimgTest;
ximgproc::qdft(qimgTest, qdftimgTest, DFT_INVERSE, false);
fs << "qidftright" << qdftimgTest;
fs.release();
#endif
dataPath = openCVExtraDir + "cv/ximgproc/qdftData.yml.gz";
FileStorage f;
f.open(dataPath, FileStorage::READ);
Mat img;
f["image"] >> img;
Mat qTest;
vector<String> nodeName = { "qdftleft","qdftright","qidftleft","qidftright" };
vector<int> flag = { 0,0,DFT_INVERSE,DFT_INVERSE };
vector<bool> leftSize = {true,false,true,false};
ximgproc::createQuaternionImage(img, img);
for (int i=0;i<static_cast<int>(nodeName.size());i++)
{
Mat test, dd;
f[nodeName[i]] >> qTest;
ximgproc::qdft(img, test, flag[i], leftSize[i]);
absdiff(test, qTest, dd);
vector<Mat> plane;
split(dd, plane);
for (auto p : plane)
{
double maxVal;
Point pIdx;
minMaxLoc(p, NULL, &maxVal, NULL, &pIdx);
ASSERT_LE(p.at<double>(pIdx), 1e-5);
}
}
}
TEST(ximgproc_matchcolortemplate, test_COLORMATCHTEMPLATE)
{
String openCVExtraDir = cvtest::TS::ptr()->get_data_path();
String dataPath = openCVExtraDir + "cv/ximgproc/corr.yml.gz";
Mat img, logo;
Mat corrRef,corr;
img = imread(openCVExtraDir + "cv/ximgproc/image.png", IMREAD_COLOR);
logo = imread(openCVExtraDir + "cv/ximgproc/opencv_logo.png", IMREAD_COLOR);
ximgproc::colorMatchTemplate(img, logo, corr);
#ifdef GENERATE_TESTDATA
FileStorage fs;
fs.open(dataPath, FileStorage::WRITE);
fs << "corr" << imgcorr;
fs.release();
#endif
FileStorage f;
f.open(dataPath, FileStorage::READ);
f["corr"] >> corrRef;
EXPECT_LE(cv::norm(corr, corrRef, NORM_INF), 1e-5);
}
}} // namespace
|