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.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
44 /* ///////////////////// pyrlk_test ///////////////////////// */
46 class CV_OptFlowPyrLKTest : public CvTest
49 CV_OptFlowPyrLKTest();
55 CV_OptFlowPyrLKTest::CV_OptFlowPyrLKTest():
56 CvTest( "optflow-pyrlk", "cvCalcOpticalFlowPyrLK" )
58 support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
61 void CV_OptFlowPyrLKTest::run( int )
65 const double success_error_level = 0.2;
66 const int bad_points_max = 2;
69 double max_err = 0., sum_err = 0;
72 int merr_i = 0, merr_j = 0, merr_k = 0;
75 CvPoint2D32f *u = 0, *v = 0, *v2 = 0;
76 CvMat *_u = 0, *_v = 0, *_v2 = 0;
84 sprintf( filename, "%soptflow/%s", ts->get_data_path(), "lk_prev.dat" );
85 _u = (CvMat*)cvLoad( filename );
89 ts->printf( CvTS::LOG, "could not read %s\n", filename );
90 code = CvTS::FAIL_MISSING_TEST_DATA;
94 sprintf( filename, "%soptflow/%s", ts->get_data_path(), "lk_next.dat" );
95 _v = (CvMat*)cvLoad( filename );
99 ts->printf( CvTS::LOG, "could not read %s\n", filename );
100 code = CvTS::FAIL_MISSING_TEST_DATA;
104 if( _u->cols != 2 || CV_MAT_TYPE(_u->type) != CV_32F ||
105 _v->cols != 2 || CV_MAT_TYPE(_v->type) != CV_32F || _v->rows != _u->rows )
107 ts->printf( CvTS::LOG, "the loaded matrices of points are not valid\n" );
108 code = CvTS::FAIL_MISSING_TEST_DATA;
113 u = (CvPoint2D32f*)_u->data.fl;
114 v = (CvPoint2D32f*)_v->data.fl;
116 /* allocate adidtional buffers */
117 _v2 = cvCloneMat( _u );
118 v2 = (CvPoint2D32f*)_v2->data.fl;
120 /* read first image */
121 sprintf( filename, "%soptflow/%s", ts->get_data_path(), "rock_1.bmp" );
122 imgI = cvLoadImage( filename, -1 );
126 ts->printf( CvTS::LOG, "could not read %s\n", filename );
127 code = CvTS::FAIL_MISSING_TEST_DATA;
131 /* read second image */
132 sprintf( filename, "%soptflow/%s", ts->get_data_path(), "rock_2.bmp" );
133 imgJ = cvLoadImage( filename, -1 );
137 ts->printf( CvTS::LOG, "could not read %s\n", filename );
138 code = CvTS::FAIL_MISSING_TEST_DATA;
143 status = (char*)cvAlloc(n*sizeof(status[0]));
146 cvCalcOpticalFlowPyrLK( imgI, imgJ, 0, 0, u, v2, n, cvSize( 20, 20 ),
147 4, status, 0, cvTermCriteria( CV_TERMCRIT_ITER|
148 CV_TERMCRIT_EPS, 30, 0.01f ), 0 );
150 /* compare results */
151 for( i = 0; i < n; i++ )
156 if( cvIsNaN(v[i].x) )
162 err = fabs(v2[i].x - v[i].x) + fabs(v2[i].y - v[i].y);
169 pt_exceed += err > success_error_level;
170 if( pt_exceed > bad_points_max )
172 ts->printf( CvTS::LOG,
173 "The number of poorly tracked points is too big (>=%d)\n", pt_exceed );
174 code = CvTS::FAIL_BAD_ACCURACY;
183 if( !cvIsNaN( v[i].x ))
187 ts->printf( CvTS::LOG, "The algorithm lost the point #%d\n", i );
188 code = CvTS::FAIL_BAD_ACCURACY;
196 ts->printf( CvTS::LOG, "Maximum tracking error is too big (=%g)\n", max_err );
197 code = CvTS::FAIL_BAD_ACCURACY;
206 cvReleaseMat( &_v2 );
208 cvReleaseImage( &imgI );
209 cvReleaseImage( &imgJ );
212 ts->set_failed_test_info( code );
215 CV_OptFlowPyrLKTest optflow_pyr_lk_test;