File: test_matchcolortemplate.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (81 lines) | stat: -rw-r--r-- 2,838 bytes parent folder | download | duplicates (3)
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