Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgproc/test/ocl/test_gftt.cpp
16344 views
1
///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
13
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
//
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
20
//
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
23
//
24
// * Redistribution's in binary form must reproduce the above copyright notice,
25
// this list of conditions and the following disclaimer in the documentation
26
// and/or other materials provided with the distribution.
27
//
28
// * The name of the copyright holders may not be used to endorse or promote products
29
// derived from this software without specific prior written permission.
30
//
31
// This software is provided by the copyright holders and contributors "as is" and
32
// any express or implied warranties, including, but not limited to, the implied
33
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34
// In no event shall the Intel Corporation or contributors be liable for any direct,
35
// indirect, incidental, special, exemplary, or consequential damages
36
// (including, but not limited to, procurement of substitute goods or services;
37
// loss of use, data, or profits; or business interruption) however caused
38
// and on any theory of liability, whether in contract, strict liability,
39
// or tort (including negligence or otherwise) arising in any way out of
40
// the use of this software, even if advised of the possibility of such damage.
41
//
42
//M*/
43
44
#include "../test_precomp.hpp"
45
#include "opencv2/ts/ocl_test.hpp"
46
47
#ifdef HAVE_OPENCL
48
49
namespace opencv_test {
50
namespace ocl {
51
52
//////////////////////////// GoodFeaturesToTrack //////////////////////////
53
54
55
PARAM_TEST_CASE(GoodFeaturesToTrack, double, bool)
56
{
57
double minDistance;
58
bool useRoi;
59
60
static const int maxCorners;
61
static const double qualityLevel;
62
63
TEST_DECLARE_INPUT_PARAMETER(src);
64
UMat points, upoints;
65
66
virtual void SetUp()
67
{
68
minDistance = GET_PARAM(0);
69
useRoi = GET_PARAM(1);
70
}
71
72
void generateTestData()
73
{
74
Mat frame = readImage("../gpu/opticalflow/rubberwhale1.png", IMREAD_GRAYSCALE);
75
ASSERT_FALSE(frame.empty()) << "could not load gpu/opticalflow/rubberwhale1.png";
76
77
Size roiSize = frame.size();
78
Border srcBorder = randomBorder(0, useRoi ? 2 : 0);
79
randomSubMat(src, src_roi, roiSize, srcBorder, frame.type(), 5, 256);
80
src_roi.copyTo(frame);
81
82
UMAT_UPLOAD_INPUT_PARAMETER(src);
83
}
84
85
void UMatToVector(const UMat & um, std::vector<Point2f> & v) const
86
{
87
v.resize(um.size().area());
88
um.copyTo(Mat(um.size(), CV_32FC2, &v[0]));
89
}
90
};
91
92
const int GoodFeaturesToTrack::maxCorners = 1000;
93
const double GoodFeaturesToTrack::qualityLevel = 0.01;
94
95
OCL_TEST_P(GoodFeaturesToTrack, Accuracy)
96
{
97
for (int j = 0; j < test_loop_times; ++j)
98
{
99
generateTestData();
100
101
std::vector<Point2f> upts, pts;
102
103
OCL_OFF(cv::goodFeaturesToTrack(src_roi, points, maxCorners, qualityLevel, minDistance, noArray()));
104
ASSERT_FALSE(points.empty());
105
UMatToVector(points, pts);
106
107
OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance));
108
ASSERT_FALSE(upoints.empty());
109
UMatToVector(upoints, upts);
110
111
ASSERT_EQ(upts.size(), pts.size());
112
113
int mistmatch = 0;
114
for (size_t i = 0; i < pts.size(); ++i)
115
{
116
Point2i a = upts[i], b = pts[i];
117
118
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1;
119
120
if (!eq)
121
++mistmatch;
122
}
123
124
double bad_ratio = static_cast<double>(mistmatch) / pts.size();
125
ASSERT_GE(1e-2, bad_ratio);
126
}
127
}
128
129
OCL_TEST_P(GoodFeaturesToTrack, EmptyCorners)
130
{
131
generateTestData();
132
usrc_roi.setTo(Scalar::all(0));
133
134
OCL_ON(cv::goodFeaturesToTrack(usrc_roi, upoints, maxCorners, qualityLevel, minDistance));
135
136
ASSERT_TRUE(upoints.empty());
137
}
138
139
OCL_INSTANTIATE_TEST_CASE_P(Imgproc, GoodFeaturesToTrack,
140
::testing::Combine(testing::Values(0.0, 3.0), Bool()));
141
142
} } // namespace opencv_test::ocl
143
144
#endif
145
146