📄 cvsumpixels.c
字号:
/*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"
#define ICV_DEF_INTEGRAL_OP_C1( flavor, arrtype, sumtype, sqsumtype, worktype, \
cast_macro, cast_sqr_macro ) \
static CvStatus CV_STDCALL \
icvIntegralImage_##flavor##_C1R( const arrtype* src, int srcstep,\
sumtype* sum, int sumstep, \
sqsumtype* sqsum, int sqsumstep,\
sumtype* tilted, int tiltedstep,\
CvSize size ) \
{ \
int x, y; \
sumtype s; \
sqsumtype sq; \
sumtype* buf = 0; \
\
srcstep /= sizeof(src[0]); \
\
memset( sum, 0, (size.width+1)*sizeof(sum[0])); \
sumstep /= sizeof(sum[0]); \
sum += sumstep + 1; \
\
if( sqsum ) \
{ \
memset( sqsum, 0, (size.width+1)*sizeof(sqsum[0])); \
sqsumstep /= sizeof(sqsum[0]); \
sqsum += sqsumstep + 1; \
} \
\
if( tilted ) \
{ \
memset( tilted, 0, (size.width+1)*sizeof(tilted[0])); \
tiltedstep /= sizeof(tilted[0]); \
tilted += tiltedstep + 1; \
} \
\
if( sqsum == 0 && tilted == 0 ) \
{ \
for( y = 0; y < size.height; y++, src += srcstep, \
sum += sumstep ) \
{ \
sum[-1] = 0; \
for( x = 0, s = 0; x < size.width; x++ ) \
{ \
sumtype t = cast_macro(src[x]); \
s += t; \
sum[x] = sum[x - sumstep] + s; \
} \
} \
} \
else if( tilted == 0 ) \
{ \
for( y = 0; y < size.height; y++, src += srcstep, \
sum += sumstep, sqsum += sqsumstep ) \
{ \
sum[-1] = 0; \
sqsum[-1] = 0; \
\
for( x = 0, s = 0, sq = 0; x < size.width; x++ ) \
{ \
worktype it = src[x]; \
sumtype t = cast_macro(it); \
sqsumtype tq = cast_sqr_macro(it); \
s += t; \
sq += tq; \
t = sum[x - sumstep] + s; \
tq = sqsum[x - sqsumstep] + sq; \
sum[x] = t; \
sqsum[x] = tq; \
} \
} \
} \
else \
{ \
if( sqsum == 0 ) \
{ \
assert(0); \
return CV_NULLPTR_ERR; \
} \
\
buf = (sumtype*)cvStackAlloc((size.width + 1 )* sizeof(buf[0]));\
sum[-1] = tilted[-1] = 0; \
sqsum[-1] = 0; \
\
for( x = 0, s = 0, sq = 0; x < size.width; x++ ) \
{ \
worktype it = src[x]; \
sumtype t = cast_macro(it); \
sqsumtype tq = cast_sqr_macro(it); \
buf[x] = tilted[x] = t; \
s += t; \
sq += tq; \
sum[x] = s; \
sqsum[x] = sq; \
} \
\
if( size.width == 1 ) \
buf[1] = 0; \
\
for( y = 1; y < size.height; y++ ) \
{ \
worktype it; \
sumtype t0; \
sqsumtype tq0; \
\
src += srcstep; \
sum += sumstep; \
sqsum += sqsumstep; \
tilted += tiltedstep; \
\
it = src[0/*x*/]; \
s = t0 = cast_macro(it); \
sq = tq0 = cast_sqr_macro(it); \
\
sum[-1] = 0; \
sqsum[-1] = 0; \
/*tilted[-1] = buf[0];*/ \
tilted[-1] = tilted[-tiltedstep]; \
\
sum[0] = sum[-sumstep] + t0; \
sqsum[0] = sqsum[-sqsumstep] + tq0; \
tilted[0] = tilted[-tiltedstep] + t0 + buf[1]; \
\
for( x = 1; x < size.width - 1; x++ ) \
{ \
sumtype t1 = buf[x]; \
buf[x-1] = t1 + t0; \
it = src[x]; \
t0 = cast_macro(it); \
tq0 = cast_sqr_macro(it); \
s += t0; \
sq += tq0; \
sum[x] = sum[x - sumstep] + s; \
sqsum[x] = sqsum[x - sqsumstep] + sq; \
t1 += buf[x+1] + t0 + tilted[x - tiltedstep - 1];\
tilted[x] = t1; \
} \
\
if( size.width > 1 ) \
{ \
sumtype t1 = buf[x]; \
buf[x-1] = t1 + t0; \
it = src[x]; /*+*/ \
t0 = cast_macro(it); \
tq0 = cast_sqr_macro(it); \
s += t0; \
sq += tq0; \
sum[x] = sum[x - sumstep] + s; \
sqsum[x] = sqsum[x - sqsumstep] + sq; \
tilted[x] = t0 + t1 + tilted[x - tiltedstep - 1];\
buf[x] = t0; \
} \
} \
} \
\
return CV_OK; \
}
ICV_DEF_INTEGRAL_OP_C1( 8u32s, uchar, int, double, int, CV_NOP, CV_8TO32F_SQR )
ICV_DEF_INTEGRAL_OP_C1( 8u64f, uchar, double, double, int, CV_8TO32F, CV_8TO32F_SQR )
ICV_DEF_INTEGRAL_OP_C1( 32f64f, float, double, double, double, CV_NOP, CV_SQR )
ICV_DEF_INTEGRAL_OP_C1( 64f, double, double, double, double, CV_NOP, CV_SQR )
#define ICV_DEF_INTEGRAL_OP_CN( flavor, arrtype, sumtype, sqsumtype, \
worktype, cast_macro, cast_sqr_macro ) \
static CvStatus CV_STDCALL \
icvIntegralImage_##flavor##_CnR( const arrtype* src, int srcstep,\
sumtype* sum, int sumstep, \
sqsumtype* sqsum, int sqsumstep,\
CvSize size, int cn ) \
{ \
int x, y; \
srcstep /= sizeof(src[0]); \
\
memset( sum, 0, (size.width+1)*cn*sizeof(sum[0])); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -