Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers matchcontours.cpp Source File

matchcontours.cpp

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                        Intel License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000, Intel Corporation, all rights reserved.
00014 // Third party copyrights are property of their respective owners.
00015 //
00016 // Redistribution and use in source and binary forms, with or without modification,
00017 // are permitted provided that the following conditions are met:
00018 //
00019 //   * Redistribution's of source code must retain the above copyright notice,
00020 //     this list of conditions and the following disclaimer.
00021 //
00022 //   * Redistribution's in binary form must reproduce the above copyright notice,
00023 //     this list of conditions and the following disclaimer in the documentation
00024 //     and/or other materials provided with the distribution.
00025 //
00026 //   * The name of Intel Corporation may not be used to endorse or promote products
00027 //     derived from this software without specific prior written permission.
00028 //
00029 // This software is provided by the copyright holders and contributors "as is" and
00030 // any express or implied warranties, including, but not limited to, the implied
00031 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00032 // In no event shall the Intel Corporation or contributors be liable for any direct,
00033 // indirect, incidental, special, exemplary, or consequential damages
00034 // (including, but not limited to, procurement of substitute goods or services;
00035 // loss of use, data, or profits; or business interruption) however caused
00036 // and on any theory of liability, whether in contract, strict liability,
00037 // or tort (including negligence or otherwise) arising in any way out of
00038 // the use of this software, even if advised of the possibility of such damage.
00039 //
00040 //M*/
00041 #include "precomp.hpp"
00042 
00043 
00044 double cv::matchShapes(InputArray contour1, InputArray contour2, int method, double)
00045 {
00046     double ma[7], mb[7];
00047     int i, sma, smb;
00048     double eps = 1.e-5;
00049     double mmm;
00050     double result = 0;
00051 
00052     HuMoments( moments(contour1), ma );
00053     HuMoments( moments(contour2), mb );
00054 
00055     switch (method)
00056     {
00057     case 1:
00058         for( i = 0; i < 7; i++ )
00059         {
00060             double ama = fabs( ma[i] );
00061             double amb = fabs( mb[i] );
00062 
00063             if( ma[i] > 0 )
00064                 sma = 1;
00065             else if( ma[i] < 0 )
00066                 sma = -1;
00067             else
00068                 sma = 0;
00069             if( mb[i] > 0 )
00070                 smb = 1;
00071             else if( mb[i] < 0 )
00072                 smb = -1;
00073             else
00074                 smb = 0;
00075 
00076             if( ama > eps && amb > eps )
00077             {
00078                 ama = 1. / (sma * log10( ama ));
00079                 amb = 1. / (smb * log10( amb ));
00080                 result += fabs( -ama + amb );
00081             }
00082         }
00083         break;
00084 
00085     case 2:
00086         for( i = 0; i < 7; i++ )
00087         {
00088             double ama = fabs( ma[i] );
00089             double amb = fabs( mb[i] );
00090 
00091             if( ma[i] > 0 )
00092                 sma = 1;
00093             else if( ma[i] < 0 )
00094                 sma = -1;
00095             else
00096                 sma = 0;
00097             if( mb[i] > 0 )
00098                 smb = 1;
00099             else if( mb[i] < 0 )
00100                 smb = -1;
00101             else
00102                 smb = 0;
00103 
00104             if( ama > eps && amb > eps )
00105             {
00106                 ama = sma * log10( ama );
00107                 amb = smb * log10( amb );
00108                 result += fabs( -ama + amb );
00109             }
00110         }
00111         break;
00112 
00113     case 3:
00114         for( i = 0; i < 7; i++ )
00115         {
00116             double ama = fabs( ma[i] );
00117             double amb = fabs( mb[i] );
00118 
00119             if( ma[i] > 0 )
00120                 sma = 1;
00121             else if( ma[i] < 0 )
00122                 sma = -1;
00123             else
00124                 sma = 0;
00125             if( mb[i] > 0 )
00126                 smb = 1;
00127             else if( mb[i] < 0 )
00128                 smb = -1;
00129             else
00130                 smb = 0;
00131 
00132             if( ama > eps && amb > eps )
00133             {
00134                 ama = sma * log10( ama );
00135                 amb = smb * log10( amb );
00136                 mmm = fabs( (ama - amb) / ama );
00137                 if( result < mmm )
00138                     result = mmm;
00139             }
00140         }
00141         break;
00142     default:
00143         CV_Error( CV_StsBadArg, "Unknown comparison method" );
00144     }
00145 
00146     return result;
00147 }
00148 
00149 
00150 CV_IMPL  double
00151 cvMatchShapes( const void* _contour1, const void* _contour2,
00152                int method, double parameter )
00153 {
00154     cv::AutoBuffer<double> abuf1, abuf2;
00155     cv::Mat contour1 = cv::cvarrToMat(_contour1, false, false, 0, &abuf1);
00156     cv::Mat contour2 = cv::cvarrToMat(_contour2, false, false, 0, &abuf2);
00157 
00158     return cv::matchShapes(contour1, contour2, method, parameter);
00159 }
00160 
00161 /* End of file. */
00162