cvnorm.cpp.svn-base

来自「非结构化路识别」· SVN-BASE 代码 · 共 943 行 · 第 1/4 页

SVN-BASE
943
字号
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                        Intel License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of Intel Corporation may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#include "_cv.h"
#include <float.h>

/****************************************************************************************\
*                                  N o r m                                               *
\****************************************************************************************/

////////////////////////////////////// Norm Declaration /////////////////////////////////

#define IPCV_DEF_NORM_CN( flavor, srctype )                                             \
IPCVAPI( CvStatus, icvNorm_Inf_##flavor##_CnCR,(const srctype* img, int imgstep,        \
                                                CvSize size, int cn,                    \
                                                int coi, double* norm ))                \
IPCVAPI( CvStatus, icvNorm_L1_##flavor##_CnCR,( const srctype* img, int imgstep,        \
                                                 CvSize size, int cn,                   \
                                                 int coi, double* norm ))               \
IPCVAPI( CvStatus, icvNorm_L2_##flavor##_CnCR,( const srctype* img, int imgstep,        \
                                                 CvSize size, int cn,                   \
                                                 int coi, double* norm ))               \
IPCVAPI( CvStatus, icvNormDiff_Inf_##flavor##_CnCR,(const srctype* img1, int imgstep1,  \
                                                    const srctype* img2, int imgstep2,  \
                                                    CvSize size, int cn,                \
                                                    int coi, double* norm ))            \
IPCVAPI( CvStatus, icvNormDiff_L1_##flavor##_CnCR,( const srctype* img1, int imgstep1,  \
                                                    const srctype* img2, int imgstep2,  \
                                                    CvSize size, int cn,                \
                                                    int coi, double* norm ))            \
IPCVAPI( CvStatus, icvNormDiff_L2_##flavor##_CnCR,( const srctype* img1, int imgstep1,  \
                                                    const srctype* img2, int imgstep2,  \
                                                    CvSize size, int cn,                \
                                                    int coi, double* norm ))            \
IPCVAPI( CvStatus, icvNorm_Inf_##flavor##_CnCMR,( const srctype* img, int imgstep,      \
                                                  const uchar* mask, int maskstep,      \
                                                  CvSize size, int cn,                  \
                                                  int coi, double* norm ))              \
IPCVAPI( CvStatus, icvNorm_L1_##flavor##_CnCMR,( const srctype* img, int imgstep,       \
                                                 const uchar* mask, int maskstep,       \
                                                 CvSize size, int cn,                   \
                                                 int coi, double* norm ))               \
IPCVAPI( CvStatus, icvNorm_L2_##flavor##_CnCMR,( const srctype* img, int imgstep,       \
                                                 const uchar* mask, int maskstep,       \
                                                 CvSize size, int cn,                   \
                                                 int coi, double* norm ))               \
IPCVAPI( CvStatus, icvNormDiff_Inf_##flavor##_CnCMR,(const srctype* img1, int imgstep1, \
                                                    const srctype* img2, int imgstep2,  \
                                                    const uchar* mask, int maskstep,    \
                                                    CvSize size, int cn,                \
                                                    int coi, double* norm ))            \
IPCVAPI( CvStatus, icvNormDiff_L1_##flavor##_CnCMR,( const srctype* img1, int imgstep1, \
                                                    const srctype* img2, int imgstep2,  \
                                                    const uchar* mask, int maskstep,    \
                                                    CvSize size, int cn,                \
                                                    int coi, double* norm ))            \
IPCVAPI( CvStatus, icvNormDiff_L2_##flavor##_CnCMR,( const srctype* img1, int imgstep1, \
                                                    const srctype* img2, int imgstep2,  \
                                                    const uchar* mask, int maskstep,    \
                                                    CvSize size, int cn,                \
                                                    int coi, double* norm ))

IPCV_DEF_NORM_CN( 8u, uchar )
IPCV_DEF_NORM_CN( 8s, char )
IPCV_DEF_NORM_CN( 16s, short )
IPCV_DEF_NORM_CN( 32s, int )
IPCV_DEF_NORM_CN( 32f, float )
IPCV_DEF_NORM_CN( 64f, double )

#undef IPCV_DEF_NORM_CN


#define ICV_DEF_NORM_CASE( _op_, _update_op_, temptype, len, cn ) \
{                                                          \
    for( x = 0; x <= (len) - 4; x += 4 )                   \
    {                                                      \
        temptype t0 = (src)[x*(cn)];                       \
        temptype t1 = (src)[(x+1)*(cn)];                   \
                                                           \
        t0 = (temptype)_op_(t0);                           \
        t1 = (temptype)_op_(t1);                           \
                                                           \
        norm = _update_op_( norm, t0 );                    \
        norm = _update_op_( norm, t1 );                    \
                                                           \
        t0 = (src)[(x+2)*(cn)];                            \
        t1 = (src)[(x+3)*(cn)];                            \
                                                           \
        t0 = (temptype)_op_(t0);                           \
        t1 = (temptype)_op_(t1);                           \
                                                           \
        norm = _update_op_( norm, t0 );                    \
        norm = _update_op_( norm, t1 );                    \
    }                                                      \
                                                           \
    for( ; x < (len); x++ )                                \
    {                                                      \
        temptype t0 = (src)[x*(cn)];                       \
        t0 = (temptype)_op_(t0);                           \
        norm = _update_op_( norm, t0 );                    \
    }                                                      \
}


#define ICV_DEF_NORM_DIFF_CASE( _op_, _diff_op_, _update_op_,       \
                                temptype, len, cn )                 \
{                                                                   \
    for( x = 0; x <= (len) - 4; x += 4 )                            \
    {                                                               \
        temptype t0 = (src1)[x*(cn)] - (src2)[x*(cn)];              \
        temptype t1 = (src1)[(x+1)*(cn)] - (src2)[(x+1)*(cn)];      \
                                                                    \
        t0 = (temptype)_diff_op_(t0);                               \
        t1 = (temptype)_diff_op_(t1);                               \
                                                                    \
        norm = _update_op_( norm, t0 );                             \
        norm = _update_op_( norm, t1 );                             \
                                                                    \
        t0 = (src1)[(x+2)*(cn)] - (src2)[(x+2)*(cn)];               \
        t1 = (src1)[(x+3)*(cn)] - (src2)[(x+3)*(cn)];               \
                                                                    \
        t0 = (temptype)_diff_op_(t0);                               \
        t1 = (temptype)_diff_op_(t1);                               \
                                                                    \
        norm = _update_op_( norm, t0 );                             \
        norm = _update_op_( norm, t1 );                             \
    }                                                               \
                                                                    \
    for( ; x < (len); x++ )                                         \
    {                                                               \
        temptype t0 = (src1)[x*(cn)] - (src2)[x*(cn)];              \
        t0 = (temptype)_diff_op_(t0);                               \
        norm = _update_op_( norm, t0 );                             \
    }                                                               \
}



#define ICV_DEF_NORM_REL_CASE( _op_, _diff_op_, _update_op_,        \
                               temptype, len, cn)                   \
{                                                                   \
    for( x = 0; x < (len); x++ )                                    \
    {                                                               \
        temptype t0 = (src2)[x*(cn)];                               \
        temptype t1 = (src1)[x*(cn)] - t0;                          \
                                                                    \
        t0 = (temptype)_op_(t0);                                    \
        t1 = (temptype)_diff_op_(t1);                               \
                                                                    \
        norm = _update_op_( norm, t0 );                             \
        norm_diff = _update_op_( norm, t1 );                        \
    }                                                               \
}



#define  CV_NORM_ENTRY( normtype )  \
    int  x;                         \
    normtype norm = 0

#define  CV_NORM_REL_ENTRY( normtype )  \
    int  x;                             \
    normtype norm = 0, norm_diff = 0

#define  CV_NORM_EXIT( cn )  *_norm = (double)norm

#define  CV_NORM_REL_EXIT( cn )  \
    *_norm = ((double)norm_diff)/((double)norm + DBL_EPSILON)

#define  CV_NORM_L2_EXIT( cn )  *_norm = sqrt((double)norm)

#define  CV_NORM_REL_L2_EXIT( cn )  \
    *_norm = sqrt((double)norm_diff)/sqrt((double)norm + DBL_EPSILON)



#define  ICV_DEF_NORM_FUNC_2D( _op_, _update_op_, _entry_, _case_, _exit_,\
                               name, srctype, normtype, temptype )  \
IPCVAPI_IMPL( CvStatus, name, ( const srctype* src, int step,       \
                                CvSize size, double* _norm ))       \
{                                                                   \
    _entry_( normtype );                                            \
                                                                    \
    for( ; size.height--; (char*&)src += step )                     \
    {                                                               \
        _case_( _op_, _update_op_, temptype, size.width, 1 );       \
    }                                                               \
                                                                    \
    _exit_(1);                                                      \
                                                                    \
    return CV_OK;                                                   \
}


#define  ICV_DEF_NORM_FUNC_2D_COI( _op_, _update_op_, _entry_, _case_, _exit_,\
                                   name, srctype, normtype, temptype )\
IPCVAPI_IMPL( CvStatus, name, ( const srctype* src, int step,       \
                      CvSize size, int cn, int coi, double* _norm ))\

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?