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.
41 #include "precomp.hpp"
43 /*F///////////////////////////////////////////////////////////////////////////////////////
44 // Name: cvMatchContours
46 // Calculates matching of the two contours
49 // contour_1 - pointer to the first input contour object.
50 // contour_2 - pointer to the second input contour object.
51 // method - method for the matching calculation
52 // (now CV_IPPI_CONTOURS_MATCH_I1, CV_CONTOURS_MATCH_I2 or
53 // CV_CONTOURS_MATCH_I3 only )
54 // rezult - output calculated measure
58 cvMatchShapes( const void* contour1, const void* contour2,
59 int method, double /*parameter*/ )
62 CvHuMoments huMoments;
69 if( !contour1 || !contour2 )
70 CV_Error( CV_StsNullPtr, "" );
72 // calculate moments of the first shape
73 cvMoments( contour1, &moments );
74 cvGetHuMoments( &moments, &huMoments );
76 ma[0] = huMoments.hu1;
77 ma[1] = huMoments.hu2;
78 ma[2] = huMoments.hu3;
79 ma[3] = huMoments.hu4;
80 ma[4] = huMoments.hu5;
81 ma[5] = huMoments.hu6;
82 ma[6] = huMoments.hu7;
85 // calculate moments of the second shape
86 cvMoments( contour2, &moments );
87 cvGetHuMoments( &moments, &huMoments );
89 mb[0] = huMoments.hu1;
90 mb[1] = huMoments.hu2;
91 mb[2] = huMoments.hu3;
92 mb[3] = huMoments.hu4;
93 mb[4] = huMoments.hu5;
94 mb[5] = huMoments.hu6;
95 mb[6] = huMoments.hu7;
101 for( i = 0; i < 7; i++ )
103 double ama = fabs( ma[i] );
104 double amb = fabs( mb[i] );
119 if( ama > eps && amb > eps )
121 ama = 1. / (sma * log10( ama ));
122 amb = 1. / (smb * log10( amb ));
123 result += fabs( -ama + amb );
131 for( i = 0; i < 7; i++ )
133 double ama = fabs( ma[i] );
134 double amb = fabs( mb[i] );
149 if( ama > eps && amb > eps )
151 ama = sma * log10( ama );
152 amb = smb * log10( amb );
153 result += fabs( -ama + amb );
161 for( i = 0; i < 7; i++ )
163 double ama = fabs( ma[i] );
164 double amb = fabs( mb[i] );
179 if( ama > eps && amb > eps )
181 ama = sma * log10( ama );
182 amb = smb * log10( amb );
183 mmm = fabs( (ama - amb) / ama );
191 CV_Error( CV_StsBadArg, "Unknown comparison method" );