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 /* This is regression test for Snakes functions of OpenCV.
45 // This test will generate fixed figure, read initial position
46 // of snake from file, run OpenCV function and compare result
47 // position of snake with position(from file) which must be resulting.
49 // Test is considered to be succesfull if resultant positions
53 class CV_SnakeTest : public CvTest
63 CV_SnakeTest::CV_SnakeTest():
64 CvTest( "snakes", "cvSnakeImage" )
66 support_testing_modes = CvTS::CORRECTNESS_CHECK_MODE;
69 void CV_SnakeTest::run( int /*start_from*/ )
72 static const char* file_name[] =
78 const int numfig_image = 1;
79 const int numfig_grad = 1;
83 #define _MAX_PATH 1024
85 char abs_file_name[_MAX_PATH];
86 char rel_path[_MAX_PATH];
91 IplImage* iplSrc = NULL;
95 float alpha,beta,gamma;
96 CvTermCriteria criteria;
98 int progress = 0, test_case_count = numfig_image + numfig_grad;
102 sprintf( rel_path, "%ssnakes/", ts->get_data_path() );
104 criteria.type = CV_TERMCRIT_ITER;
105 win.height = win.width = 3;
107 for( i = 0; i < test_case_count; i++ )
114 ts->update_context( this, i, false );
116 /* create full name of bitmap file */
117 strcpy(tmp, rel_path);
118 strcat(tmp, file_name[i]);
119 strcpy( abs_file_name, tmp );
120 strcat( abs_file_name, ".bmp" );
122 /* read bitmap with 8u image */
123 iplSrc = cvLoadImage( abs_file_name, -1 );
127 ts->printf( CvTS::LOG, "can not load %s\n", abs_file_name );
128 code = CvTS::FAIL_MISSING_TEST_DATA;
132 /* init snake reading file with snake */
133 strcpy(tmp, rel_path);
134 strcat(tmp, file_name[i]);
135 strcpy( abs_file_name, tmp );
136 strcat( abs_file_name, ".txt" );
139 file = fopen( abs_file_name, "r" );
141 file = fopen( abs_file_name, "r+" );
146 ts->printf( CvTS::LOG, "can not load %s\n", abs_file_name );
147 code = CvTS::FAIL_MISSING_TEST_DATA;
151 /* read snake parameters */
152 fscanf(file, "%d", &length );
153 fscanf(file, "%f", &alpha );
154 fscanf(file, "%f", &beta );
155 fscanf(file, "%f", &gamma );
157 /* allocate memory for snakes */
158 Pts = (CvPoint*)cvAlloc( length * sizeof(Pts[0]) );
159 resPts = (CvPoint*)cvAlloc( length * sizeof(resPts[0]) );
161 /* get number of snake positions */
162 fscanf(file, "%d", &num_pos );
164 /* get number iterations between two positions */
165 fscanf(file, "%d", &criteria.max_iter );
167 /* read initial snake position */
168 for ( j = 0; j < length; j++ )
170 fscanf(file, "%d%d", &Pts[j].x, &Pts[j].y );
173 for ( k = 0; k < num_pos; k++ )
175 /* Run CVL function to check it */
178 cvSnakeImage( iplSrc, Pts, length,
179 &alpha, &beta, &gamma, CV_VALUE, win, criteria, 0 );
183 cvSnakeImage( iplSrc, Pts, length,
184 &alpha, &beta, &gamma, CV_VALUE, win, criteria, 1 /*usegrad*/ );
188 for ( j = 0; j < length; j++ )
190 fscanf(file, "%d%d", &resPts[j].x, &resPts[j].y );
192 lErrors += (Pts[j].x != resPts[j].x);
193 lErrors += (Pts[j].y != resPts[j].y);
196 fseek( file, 0, SEEK_CUR );
198 for ( j = 0; j < length; j++ )
200 fprintf(file, "\n%d %d", Pts[j].x, Pts[j].y );
208 cvReleaseImage(&iplSrc);
210 progress = update_progress( progress, i, test_case_count, 0 );
215 ts->printf( CvTS::LOG, "Total fixed %d errors", lErrors );
216 code = CvTS::FAIL_BAD_ACCURACY;
226 cvReleaseImage(&iplSrc);
229 ts->set_failed_test_info( code );
232 CV_SnakeTest snake_test;