1 ///////////////////////////////////////////////////////////////////////////////////////
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
12 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
13 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
14 // Third party copyrights are property of their respective owners.
17 // Jin Ma, jin@multicorewareinc.com
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
22 // * Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
25 // * Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other oclMaterials provided with the distribution.
29 // * The name of the copyright holders may not be used to endorse or promote products
30 // derived from this software without specific prior written permission.
32 // This software is provided by the copyright holders and contributors "as is" and
33 // any express or implied warranties, including, but not limited to, the implied
34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
35 // In no event shall the Intel Corporation or contributors be liable for any direct,
36 // indirect, incidental, special, exemplary, or consequential damages
37 // (including, but not limited to, procurement of substitute goods or services;
38 // loss of use, data, or profits; or business interruption) however caused
39 // and on any theory of liability, whether in contract, strict liability,
40 // or tort (including negligence or otherwise) arising in any way out of
41 // the use of this software, even if advised of the possibility of such damage.
45 #include "test_precomp.hpp"
52 using namespace cv::ocl;
53 using namespace cvtest;
54 using namespace testing;
57 //////////////////////////////////////////////////////////////////////////
59 PARAM_TEST_CASE(Kalman, int, int)
66 iteration = GET_PARAM(1);
70 OCL_TEST_P(Kalman, Accuracy)
72 const int Dim = size_;
73 const int Steps = iteration;
74 const double max_init = 1;
75 const double max_noise = 0.1;
77 Mat sample_mat(Dim, 1, CV_32F), temp_mat;
78 oclMat Sample(Dim, 1, CV_32F);
79 oclMat Temp(Dim, 1, CV_32F);
80 Mat Temp_cpu(Dim, 1, CV_32F);
82 Size size(Sample.cols, Sample.rows);
84 sample_mat = randomMat(size, Sample.type(), -max_init, max_init, false);
85 Sample.upload(sample_mat);
88 cv::ocl::KalmanFilter kalman_filter_ocl;
89 kalman_filter_ocl.init(Dim, Dim);
91 cv::ocl::setIdentity(kalman_filter_ocl.errorCovPre, 1);
92 cv::ocl::setIdentity(kalman_filter_ocl.measurementMatrix, 1);
93 cv::ocl::setIdentity(kalman_filter_ocl.errorCovPost, 1);
95 kalman_filter_ocl.measurementNoiseCov.setTo(Scalar::all(0));
96 kalman_filter_ocl.statePre.setTo(Scalar::all(0));
97 kalman_filter_ocl.statePost.setTo(Scalar::all(0));
99 kalman_filter_ocl.correct(Sample);
103 cv::KalmanFilter kalman_filter_cpu;
105 kalman_filter_cpu.init(Dim, Dim);
107 cv::setIdentity(kalman_filter_cpu.errorCovPre, 1);
108 cv::setIdentity(kalman_filter_cpu.measurementMatrix, 1);
109 cv::setIdentity(kalman_filter_cpu.errorCovPost, 1);
111 kalman_filter_cpu.measurementNoiseCov.setTo(Scalar::all(0));
112 kalman_filter_cpu.statePre.setTo(Scalar::all(0));
113 kalman_filter_cpu.statePost.setTo(Scalar::all(0));
115 kalman_filter_cpu.correct(sample_mat);
118 for(int i = 0; i<Steps; i++)
120 kalman_filter_ocl.predict();
121 kalman_filter_cpu.predict();
123 cv::gemm(kalman_filter_cpu.transitionMatrix, sample_mat, 1, cv::Mat(), 0, Temp_cpu);
125 Size size1(Temp.cols, Temp.rows);
126 Mat temp = randomMat(size1, Temp.type(), 0, 0xffff, false);
129 cv::multiply(2, temp, temp);
131 cv::subtract(temp, 1, temp);
133 cv::multiply(max_noise, temp, temp);
135 cv::add(temp, Temp_cpu, Temp_cpu);
137 Temp.upload(Temp_cpu);
139 Temp_cpu.copyTo(sample_mat);
141 kalman_filter_ocl.correct(Temp);
142 kalman_filter_cpu.correct(Temp_cpu);
145 EXPECT_MAT_NEAR(kalman_filter_cpu.statePost, kalman_filter_ocl.statePost, 0);
148 INSTANTIATE_TEST_CASE_P(OCL_Video, Kalman, Combine(Values(3, 7), Values(30)));
150 #endif // HAVE_CLAMDBLAS
152 #endif // HAVE_OPENCL