⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cxmean.cpp

📁 opencv库在TI DM6437上的移植,目前包括两个库cv.lib和cxcore.lib的工程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*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 "_cxcore.h"
#include <float.h>

/****************************************************************************************\
*                              Mean value over the region                                *
\****************************************************************************************/

#define ICV_MEAN_CASE_C1( len )         \
    for( ; x <= (len) - 2; x += 2 )     \
    {                                   \
        if( mask[x] )                   \
             s0 += src[x], pix++;       \
        if( mask[x+1] )                 \
            s0 += src[x+1], pix++;      \
    }                                   \
                                        \
    for( ; x < (len); x++ )             \
        if( mask[x] )                   \
            s0 += src[x], pix++


#define ICV_MEAN_CASE_C2( len )         \
    for( ; x < (len); x++ )             \
        if( mask[x] )                   \
        {                               \
            s0 += src[x*2];             \
            s1 += src[x*2+1];           \
            pix++;                      \
        }


#define ICV_MEAN_CASE_C3( len )         \
    for( ; x < (len); x++ )             \
        if( mask[x] )                   \
        {                               \
            s0 += src[x*3];             \
            s1 += src[x*3+1];           \
            s2 += src[x*3+2];           \
            pix++;                      \
        }


#define ICV_MEAN_CASE_C4( len )         \
    for( ; x < (len); x++ )             \
        if( mask[x] )                   \
        {                               \
            s0 += src[x*4];             \
            s1 += src[x*4+1];           \
            s2 += src[x*4+2];           \
            s3 += src[x*4+3];           \
            pix++;                      \
        }


#define ICV_MEAN_COI_CASE( len, cn )    \
    for( ; x <= (len) - 2; x += 2 )     \
    {                                   \
        if( mask[x] )                   \
             s0 += src[x*(cn)], pix++;  \
        if( mask[x+1] )                 \
            s0+=src[(x+1)*(cn)], pix++; \
    }                                   \
                                        \
    for( ; x < (len); x++ )             \
        if( mask[x] )                   \
            s0 += src[x*(cn)], pix++;


////////////////////////////////////// entry macros //////////////////////////////////////

#define ICV_MEAN_ENTRY_COMMON()         \
    int pix = 0;                        \
    step /= sizeof(src[0])

#define ICV_MEAN_ENTRY_C1( sumtype )    \
    sumtype s0 = 0;                     \
    ICV_MEAN_ENTRY_COMMON()

#define ICV_MEAN_ENTRY_C2( sumtype )    \
    sumtype s0 = 0, s1 = 0;             \
    ICV_MEAN_ENTRY_COMMON()

#define ICV_MEAN_ENTRY_C3( sumtype )    \
    sumtype s0 = 0, s1 = 0, s2 = 0;     \
    ICV_MEAN_ENTRY_COMMON()

#define ICV_MEAN_ENTRY_C4( sumtype )        \
    sumtype s0 = 0, s1 = 0, s2 = 0, s3 = 0; \
    ICV_MEAN_ENTRY_COMMON()


#define ICV_MEAN_ENTRY_BLOCK_COMMON( block_size ) \
    int remaining = block_size;                   \
    ICV_MEAN_ENTRY_COMMON()

#define ICV_MEAN_ENTRY_BLOCK_C1( sumtype, worktype, block_size )\
    sumtype sum0 = 0;                                           \
    worktype s0 = 0;                                            \
    ICV_MEAN_ENTRY_BLOCK_COMMON( block_size )

#define ICV_MEAN_ENTRY_BLOCK_C2( sumtype, worktype, block_size )\
    sumtype sum0 = 0, sum1 = 0;                                 \
    worktype s0 = 0, s1 = 0;                                    \
    ICV_MEAN_ENTRY_BLOCK_COMMON( block_size )

#define ICV_MEAN_ENTRY_BLOCK_C3( sumtype, worktype, block_size )\
    sumtype sum0 = 0, sum1 = 0, sum2 = 0;                       \
    worktype s0 = 0, s1 = 0, s2 = 0;                            \
    ICV_MEAN_ENTRY_BLOCK_COMMON( block_size )

#define ICV_MEAN_ENTRY_BLOCK_C4( sumtype, worktype, block_size )\
    sumtype sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;             \
    worktype s0 = 0, s1 = 0, s2 = 0, s3 = 0;                    \
    ICV_MEAN_ENTRY_BLOCK_COMMON( block_size )


/////////////////////////////////////// exit macros //////////////////////////////////////

#define ICV_MEAN_EXIT_COMMON()          \
    double scale = pix ? 1./pix : 0

#define ICV_MEAN_EXIT_C1( tmp )         \
    ICV_MEAN_EXIT_COMMON();             \
    mean[0] = scale*(double)tmp##0

#define ICV_MEAN_EXIT_C2( tmp )         \
    ICV_MEAN_EXIT_COMMON();             \
    double t0 = scale*(double)tmp##0;   \
    double t1 = scale*(double)tmp##1;   \
    mean[0] = t0;                       \
    mean[1] = t1

#define ICV_MEAN_EXIT_C3( tmp )         \
    ICV_MEAN_EXIT_COMMON();             \
    double t0 = scale*(double)tmp##0;   \
    double t1 = scale*(double)tmp##1;   \
    double t2 = scale*(double)tmp##2;   \
    mean[0] = t0;                       \
    mean[1] = t1;                       \
    mean[2] = t2

#define ICV_MEAN_EXIT_C4( tmp )         \
    ICV_MEAN_EXIT_COMMON();             \
    double t0 = scale*(double)tmp##0;   \
    double t1 = scale*(double)tmp##1;   \
    mean[0] = t0;                       \
    mean[1] = t1;                       \
    t0 = scale*(double)tmp##2;          \
    t1 = scale*(double)tmp##3;          \
    mean[2] = t0;                       \
    mean[3] = t1

#define ICV_MEAN_EXIT_BLOCK_C1()    \
    sum0 += s0;                     \
    ICV_MEAN_EXIT_C1( sum )

#define ICV_MEAN_EXIT_BLOCK_C2()    \
    sum0 += s0; sum1 += s1;         \
    ICV_MEAN_EXIT_C2( sum )

#define ICV_MEAN_EXIT_BLOCK_C3()    \
    sum0 += s0; sum1 += s1;         \
    sum2 += s2;                     \
    ICV_MEAN_EXIT_C3( sum )

#define ICV_MEAN_EXIT_BLOCK_C4()    \
    sum0 += s0; sum1 += s1;         \
    sum2 += s2; sum3 += s3;         \
    ICV_MEAN_EXIT_C4( sum )

////////////////////////////////////// update macros /////////////////////////////////////

#define ICV_MEAN_UPDATE_COMMON( block_size )\
    remaining = block_size

#define ICV_MEAN_UPDATE_C1( block_size )    \
    ICV_MEAN_UPDATE_COMMON( block_size );   \
    sum0 += s0;                             \
    s0 = 0

#define ICV_MEAN_UPDATE_C2( block_size )    \
    ICV_MEAN_UPDATE_COMMON( block_size );   \
    sum0 += s0; sum1 += s1;                 \
    s0 = s1 = 0

#define ICV_MEAN_UPDATE_C3( block_size )    \
    ICV_MEAN_UPDATE_COMMON( block_size );   \
    sum0 += s0; sum1 += s1; sum2 += s2;     \
    s0 = s1 = s2 = 0

#define ICV_MEAN_UPDATE_C4( block_size )    \
    ICV_MEAN_UPDATE_COMMON( block_size );   \
    sum0 += s0; sum1 += s1;                 \
    sum2 += s2; sum3 += s3;                 \
    s0 = s1 = s2 = s3 = 0


#define ICV_IMPL_MEAN_BLOCK_FUNC_2D( flavor, cn,                \
    arrtype, sumtype, worktype, block_size )                    \
IPCVAPI_IMPL( CvStatus, icvMean_##flavor##_C##cn##MR,           \

⌨️ 快捷键说明

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