1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11
// For Open Source Computer Vision Library
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
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16
// Third party copyrights are property of their respective owners.
18
// Redistribution and use in source and binary forms, with or without modification,
19
// are permitted provided that the following conditions are met:
21
// * Redistribution's of source code must retain the above copyright notice,
22
// this list of conditions and the following disclaimer.
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.
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.
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.
45
#include "../test_precomp.hpp"
46
#include "opencv2/ts/ocl_test.hpp"
55
/////////////////////////////////////////////////////////////////////////////////////////////////
58
PARAM_TEST_CASE(PyrLKOpticalFlow, int, int)
62
TermCriteria criteria;
64
double minEigThreshold;
68
winSize = Size(GET_PARAM(0), GET_PARAM(0));
69
maxLevel = GET_PARAM(1);
70
criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01);
72
minEigThreshold = 1e-4f;
76
OCL_TEST_P(PyrLKOpticalFlow, Mat)
78
static const int npoints = 1000;
79
static const float eps = 0.03f;
81
cv::Mat frame0 = readImage("optflow/RubberWhale1.png", cv::IMREAD_GRAYSCALE);
82
ASSERT_FALSE(frame0.empty());
83
UMat umatFrame0; frame0.copyTo(umatFrame0);
85
cv::Mat frame1 = readImage("optflow/RubberWhale2.png", cv::IMREAD_GRAYSCALE);
86
ASSERT_FALSE(frame1.empty());
87
UMat umatFrame1; frame1.copyTo(umatFrame1);
89
std::vector<cv::Point2f> pts;
90
cv::goodFeaturesToTrack(frame0, pts, npoints, 0.01, 0.0);
92
std::vector<cv::Point2f> cpuNextPts;
93
std::vector<unsigned char> cpuStatusCPU;
94
std::vector<float> cpuErr;
95
OCL_OFF(cv::calcOpticalFlowPyrLK(frame0, frame1, pts, cpuNextPts, cpuStatusCPU, cpuErr, winSize, maxLevel, criteria, flags, minEigThreshold));
97
UMat umatNextPts, umatStatus, umatErr;
98
OCL_ON(cv::calcOpticalFlowPyrLK(umatFrame0, umatFrame1, pts, umatNextPts, umatStatus, umatErr, winSize, maxLevel, criteria, flags, minEigThreshold));
99
std::vector<cv::Point2f> nextPts; umatNextPts.reshape(2, 1).copyTo(nextPts);
100
std::vector<unsigned char> status; umatStatus.reshape(1, 1).copyTo(status);
101
std::vector<float> err; umatErr.reshape(1, 1).copyTo(err);
103
ASSERT_EQ(cpuNextPts.size(), nextPts.size());
104
ASSERT_EQ(cpuStatusCPU.size(), status.size());
106
size_t mistmatch = 0;
107
for (size_t i = 0; i < nextPts.size(); ++i)
109
if (status[i] != cpuStatusCPU[i])
117
cv::Point2i a = nextPts[i];
118
cv::Point2i b = cpuNextPts[i];
120
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1;
121
float errdiff = 0.0f;
123
if (!eq || errdiff > 1e-1)
128
double bad_ratio = static_cast<double>(mistmatch) / (nextPts.size());
130
ASSERT_LE(bad_ratio, eps);
133
OCL_INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlow,
140
} } // namespace cvtest::ocl
143
#endif // HAVE_OPENCL
b'\\ No newline at end of file'