Skip to content

Commit 8603a1e

Browse files
committed
Add test
1 parent 849eb70 commit 8603a1e

File tree

3 files changed

+98
-24
lines changed

3 files changed

+98
-24
lines changed

modules/ximgproc/samples/color_match_template.cpp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <iostream>
2+
#include <fstream>
23
#include <opencv2/core.hpp>
34
#include <opencv2/core/utility.hpp>
45
#include <opencv2/highgui.hpp>
@@ -52,23 +53,35 @@ static void UpdateThreshImage(int , void *r)
5253

5354
imshow("Max Quaternion corr",dst);
5455
}
56+
vector<Vec4d> LectureFichier(string s)
57+
{
58+
fstream f;
59+
vector<Vec4d> q;
60+
f.open(s, ios::in);
61+
int nbQuat;
62+
f >> nbQuat;
63+
f >> nbQuat;
64+
nbQuat = nbQuat * nbQuat;
65+
for (int i = 0; i < nbQuat; i++)
66+
{
67+
Vec4d v;
68+
f >> v[0] >> v[1] >> v[2] >> v[3];
69+
q.push_back(v);
70+
}
71+
return q;
72+
}
73+
74+
5575

5676
int main(int , char *[])
5777
{
58-
#define TESTMATCHING
59-
60-
#ifdef TESTMATCHING
6178
Mat imgLogo = imread("g:/lib/opencv/samples/data/opencv-logo.png", IMREAD_COLOR);
62-
Mat fruits = imread("g:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
63-
fruits = fruits ;
64-
// resize(fruits,fruits, Size(), 0.5, 0.5);
79+
Mat imgColor = imread("g:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
80+
// DUPLICATE OPENCV LOGO CHANGING COLOR
6581
Mat img,colorTemplate;
6682
imgLogo(Rect(0, 0, imgLogo.cols, 580)).copyTo(img);
6783
resize(img, colorTemplate, Size(), 0.05, 0.05);
6884
vector<Mat> colorMask(4);
69-
inRange(colorTemplate, Vec3b(255, 255, 255), Vec3b(255, 255, 255), colorMask[0]);
70-
// colorTemplate.setTo(Scalar(0,0,0), colorMask[0]);
71-
7285
inRange(colorTemplate, Vec3b(255, 0, 0), Vec3b(255, 0, 0), colorMask[0]);
7386
inRange(colorTemplate, Vec3b(0, 255, 0), Vec3b(0,255, 0), colorMask[1]);
7487
inRange(colorTemplate, Vec3b( 0, 0,255), Vec3b( 0, 0,255), colorMask[2]);
@@ -86,24 +99,23 @@ int main(int , char *[])
8699
}
87100
else
88101
ps.pRef.push_back(p);
89-
newLogo.copyTo(fruits(Rect(p.x, p.y, newLogo.cols, newLogo.rows)));
102+
newLogo.copyTo(imgColor(Rect(p.x, p.y, newLogo.cols, newLogo.rows)));
90103

91104
}
92-
#else
93-
Mat fruits = imread("c2.png", IMREAD_COLOR);
94-
Mat colorTemplate = imread("c1.png", IMREAD_COLOR);
95-
Mat img= colorTemplate;
96-
#endif
97-
imshow("Image", fruits);
105+
imshow("Image", imgColor);
98106
imshow("opencv_logo", colorTemplate);
99-
107+
imwrite("g:/image.png", imgColor);
108+
Mat colorRef(imgColor.size(), imgColor.type(),Scalar::all(0));
109+
colorTemplate.copyTo(colorRef(Rect(0, 0, colorTemplate.cols, colorTemplate.rows)));
110+
imwrite("g:/opencv_logo.png", colorRef);
100111
if (img.empty())
101112
{
102113
cout << "Cannot load image file\n";
103114
return 0;
104115
}
116+
// OK NOW WHERE IS OPENCV LOGO ?
105117
Mat imgcorr;
106-
ximgproc::colorMatchTemplate(fruits, colorTemplate, imgcorr);
118+
ximgproc::colorMatchTemplate(imgColor, colorTemplate, imgcorr);
107119
imshow("quaternion correlation real", imgcorr);
108120
normalize(imgcorr, imgcorr,1,0,NORM_MINMAX);
109121
imgcorr.convertTo(ps.img, CV_8U, 255);
@@ -115,9 +127,6 @@ int main(int , char *[])
115127
code = waitKey(50);
116128
}
117129

118-
FileStorage fs("corr.yml", FileStorage::WRITE);
119-
fs<<"Image"<< imgcorr;
120-
fs.release();
121130
waitKey(0);
122131
return 0;
123132
}

modules/ximgproc/src/quaternion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void createQuaternionImage(InputArray _img, OutputArray _qimg)
1515
split(_img, plane);
1616
qplane[0] = Mat::zeros(_img.size(), CV_64FC1);
1717
for (int i = 0; i < cn; i++)
18-
plane[i].convertTo(qplane[i + 1], CV_64F);
18+
plane[i].convertTo(qplane[3-i], CV_64F);
1919
merge(qplane, _qimg);
2020
}
2121

@@ -90,8 +90,8 @@ void qdft(InputArray _img, OutputArray _qimg, int flags, bool sideLeft)
9090
merge(vc2, c2);
9191
if (flags& DFT_INVERSE)
9292
{
93-
dft(c1, C1, DFT_COMPLEX_OUTPUT | DFT_INVERSE);
94-
dft(c2, C2, DFT_COMPLEX_OUTPUT | DFT_INVERSE);
93+
dft(c1, C1, DFT_COMPLEX_OUTPUT | DFT_INVERSE|DFT_SCALE);
94+
dft(c2, C2, DFT_COMPLEX_OUTPUT | DFT_INVERSE | DFT_SCALE);
9595
}
9696
else
9797
{
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include "test_precomp.hpp"
6+
7+
namespace opencv_test { namespace {
8+
9+
10+
TEST(ximpgroc_matchcolortemplate,test_QFFT)
11+
{
12+
String openCVExtraDir = cvtest::TS::ptr()->get_data_path();
13+
String dataPath = openCVExtraDir+"cv/ximgproc/qdftData.yml.gz";
14+
FileStorage f;
15+
f.open(dataPath, FileStorage::READ);
16+
Mat img;
17+
f["image"] >> img;
18+
Mat qTest;
19+
vector<String> nodeName = { "qdftleft","qdftright","qidftleft","qidftright" };
20+
vector<int> flag = { 0,0,DFT_INVERSE,DFT_INVERSE };
21+
vector<bool> leftSize = {true,false,true,false};
22+
ximgproc::createQuaternionImage(img, img);
23+
for (int i=0;i<nodeName.size();i++)
24+
{
25+
Mat test, dd;
26+
f[nodeName[i]] >> qTest;
27+
ximgproc::qdft(img, test, flag[i], leftSize[i]);
28+
absdiff(test, qTest, dd);
29+
vector<Mat> plane;
30+
split(dd, plane);
31+
for (auto p : plane)
32+
{
33+
double maxVal;
34+
Point pIdx;
35+
minMaxLoc(p, NULL, &maxVal, NULL, &pIdx);
36+
ASSERT_LE(p.at<double>(pIdx), 1e-5);
37+
}
38+
39+
}
40+
}
41+
42+
TEST(ximpgroc_matchcolortemplate, test_COLORMATCHTEMPLATE)
43+
{
44+
String openCVExtraDir = cvtest::TS::ptr()->get_data_path();
45+
String dataPath = openCVExtraDir + "cv/ximgproc/corr.yml.gz";
46+
FileStorage f;
47+
f.open(dataPath, FileStorage::READ);
48+
Mat corrRef,corr,dd;
49+
f["corr"] >> corrRef;
50+
Mat img, logo;
51+
img = imread(openCVExtraDir + "cv/ximgproc/image.png", IMREAD_COLOR);
52+
logo = imread(openCVExtraDir + "cv/ximgproc/opencv_logo.png", IMREAD_COLOR);
53+
ximgproc::colorMatchTemplate(img, logo, corr);
54+
55+
absdiff(corr, corrRef, dd);
56+
double maxVal;
57+
Point pIdx;
58+
minMaxLoc(dd, NULL, &maxVal, NULL, &pIdx);
59+
ASSERT_LE(maxVal, 1e-5);
60+
61+
}
62+
63+
64+
65+
}} // namespace

0 commit comments

Comments
 (0)