OpenCv库函数(types_c.h)持续更新

本文介绍了OpenCV中的IplImage结构体,包括origin、dataOrder、widthStep和roi等关键参数的含义,并讨论了结构元素IplConvKernel的创建与使用,如形状类型、锚点和自定义结构元素的操作。
摘要由CSDN通过智能技术生成



#ifndef __OPENCV_CORE_TYPES_H__
#define __OPENCV_CORE_TYPES_H__


#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER
#  if _MSC_VER > 1300
#    define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
#  endif
#endif




#ifndef SKIP_INCLUDES


#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>


#if !defined _MSC_VER && !defined __BORLANDC__
#  include <stdint.h>
#endif


#if defined __ICL
#  define CV_ICC   __ICL
#elif defined __ICC
#  define CV_ICC   __ICC
#elif defined __ECL
#  define CV_ICC   __ECL
#elif defined __ECC
#  define CV_ICC   __ECC
#elif defined __INTEL_COMPILER
#  define CV_ICC   __INTEL_COMPILER
#endif


#if defined CV_ICC && !defined CV_ENABLE_UNROLLED
#  define CV_ENABLE_UNROLLED 0
#else
#  define CV_ENABLE_UNROLLED 1
#endif


#if (defined _M_X64 && defined _MSC_VER && _MSC_VER >= 1400) || (__GNUC__ >= 4 && defined __x86_64__)
#  if defined WIN32
#    include <intrin.h>
#  endif
#  if defined __SSE2__ || !defined __GNUC__
#    include <emmintrin.h>
#  endif
#endif


#if defined __BORLANDC__
#  include <fastmath.h>
#else
#  include <math.h>
#endif


#ifdef HAVE_IPL
#  ifndef __IPL_H__
#    if defined WIN32 || defined _WIN32
#      include <ipl.h>
#    else
#      include <ipl/ipl.h>
#    endif
#  endif
#elif defined __IPL_H__
#  define HAVE_IPL
#endif


#endif // SKIP_INCLUDES


#if defined WIN32 || defined _WIN32
#  define CV_CDECL __cdecl
#  define CV_STDCALL __stdcall
#else
#  define CV_CDECL
#  define CV_STDCALL
#endif


#ifndef CV_EXTERN_C
#  ifdef __cplusplus
#    define CV_EXTERN_C extern "C"
#    define CV_DEFAULT(val) = val
#  else
#    define CV_EXTERN_C
#    define CV_DEFAULT(val)
#  endif
#endif


#ifndef CV_EXTERN_C_FUNCPTR
#  ifdef __cplusplus
#    define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
#  else
#    define CV_EXTERN_C_FUNCPTR(x) typedef x
#  endif
#endif


#ifndef CV_INLINE
#  if defined __cplusplus
#    define CV_INLINE inline
#  elif defined _MSC_VER
#    define CV_INLINE __inline
#  else
#    define CV_INLINE static
#  endif
#endif /* CV_INLINE */


#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
#  define CV_EXPORTS __declspec(dllexport)
#else
#  define CV_EXPORTS
#endif


#ifndef CVAPI
#  define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
#endif


#if defined _MSC_VER || defined __BORLANDC__
   typedef __int64 int64;
   typedef unsigned __int64 uint64;
#  define CV_BIG_INT(n)   n##I64
#  define CV_BIG_UINT(n)  n##UI64
#else
   typedef int64_t int64;
   typedef uint64_t uint64;
#  define CV_BIG_INT(n)   n##LL
#  define CV_BIG_UINT(n)  n##ULL
#endif


#ifndef HAVE_IPL
   typedef unsigned char uchar;
   typedef unsigned short ushort;
#endif


typedef signed char schar;


/* special informative macros for wrapper generators */
#define CV_CARRAY(counter)
#define CV_CUSTOM_CARRAY(args)
#define CV_EXPORTS_W CV_EXPORTS
#define CV_EXPORTS_W_SIMPLE CV_EXPORTS
#define CV_EXPORTS_AS(synonym) CV_EXPORTS
#define CV_EXPORTS_W_MAP CV_EXPORTS
#define CV_IN_OUT
#define CV_OUT
#define CV_PROP
#define CV_PROP_RW
#define CV_WRAP
#define CV_WRAP_AS(synonym)
#define CV_WRAP_DEFAULT(value)


/* CvArr* is used to pass arbitrary
 * array-like data structures
 * into functions where the particular
 * array type is recognized at runtime:
 */
typedef void CvArr;


typedef union Cv32suf
{
    int i;
    unsigned u;
    float f;
}
Cv32suf;


typedef union Cv64suf
{
    int64 i;
    uint64 u;
    double f;
}
Cv64suf;


typedef int CVStatus;


enum {
 CV_StsOk=                       0,  /* everithing is ok                */
 CV_StsBackTrace=               -1,  /* pseudo error for back trace     */
 CV_StsError=                   -2,  /* unknown /unspecified error      */
 CV_StsInternal=                -3,  /* internal error (bad state)      */
 CV_StsNoMem=                   -4,  /* insufficient memory             */
 CV_StsBadArg=                  -5,  /* function arg/param is bad       */
 CV_StsBadFunc=                 -6,  /* unsupported function            */
 CV_StsNoConv=                  -7,  /* iter. didn't converge           */
 CV_StsAutoTrace=               -8,  /* tracing                         */
 CV_HeaderIsNull=               -9,  /* image header is NULL            */
 CV_BadImageSize=              -10, /* image size is invalid           */
 CV_BadOffset=                 -11, /* offset is invalid               */
 CV_BadDataPtr=                -12, /**/
 CV_BadStep=                   -13, /**/
 CV_BadModelOrChSeq=           -14, /**/
 CV_BadNumChannels=            -15, /**/
 CV_BadNumChannel1U=           -16, /**/
 CV_BadDepth=                  -17, /**/
 CV_BadAlphaChannel=           -18, /**/
 CV_BadOrder=                  -19, /**/
 CV_BadOrigin=                 -20, /**/
 CV_BadAlign=                  -21, /**/
 CV_BadCallBack=               -22, /**/
 CV_BadTileSize=               -23, /**/
 CV_BadCOI=                    -24, /**/
 CV_BadROISize=                -25, /**/
 CV_MaskIsTiled=               -26, /**/
 CV_StsNullPtr=                -27, /* null pointer */
 CV_StsVecLengthErr=           -28, /* incorrect vector length */
 CV_StsFilterStructContentErr= -29, /* incorr. filter structure content */
 CV_StsKernelStructContentErr= -30, /* incorr. transform kernel content */
 CV_StsFilterOffsetErr=        -31, /* incorrect filter offset value */
 CV_StsBadSize=                -201, /* the input/output structure size is incorrect  */
 CV_StsDivByZero=              -202, /* division by zero */
 CV_StsInplaceNotSupported=    -203, /* in-place operation is not supported */
 CV_StsObjectNotFound=         -204, /* request can't be completed */
 CV_StsUnmatchedFormats=       -205, /* formats of input/output arrays differ */
 CV_StsBadFlag=                -206, /* flag is wrong or not supported */
 CV_StsBadPoint=               -207, /* bad CvPoint */
 CV_StsBadMask=                -208, /* bad format of mask (neither 8uC1 nor 8sC1)*/
 CV_StsUnmatchedSizes=         -209, /* sizes of input/output structures do not match */
 CV_StsUnsupportedFormat=      -210, /* the data format/type is not supported by the function*/
 CV_StsOutOfRange=             -211, /* some of parameters are out of range */
 CV_StsParseError=             -212, /* invalid syntax/structure of the parsed file */
 CV_StsNotImplemented=         -213, /* the requested function/feature is not implemented */
 CV_StsBadMemBlock=            -214, /* an allocated block has been corrupted */
 CV_StsAssert=                 -215, /* assertion failed */
 CV_GpuNotSupported=           -216,
 CV_GpuApiCallError=           -217,
 CV_OpenGlNotSupported=        -218,
 CV_OpenGlApiCallError=        -219,
 CV_OpenCLDoubleNotSupported=  -220,
 CV_OpenCLInitError=           -221,
 CV_OpenCLNoAMDBlasFft=        -222
};


/****************************************************************************************\
*                             Common macros and inline functions                         *
\****************************************************************************************/


#ifdef HAVE_TEGRA_OPTIMIZATION
#  include "tegra_round.hpp"
#endif


#define CV_PI   3.1415926535897932384626433832795
#define CV_LOG2 0.69314718055994530941723212145818


#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))    //交换


#ifndef MIN
#  define MIN(a,b)  ((a) > (b) ? (b) : (a))                       //最小
#endif


#ifndef MAX
#  define MAX(a,b)  ((a) < (b) ? (b) : (a))                     //最大
#endif


/* min & max without jumps */
#define  CV_IMIN(a, b)  ((a) ^ (((a)^(b)) & (((a) < (b)) - 1)))


#define  CV_IMAX(a, b)  ((a) ^ (((a)^(b)) & (((a) > (b)) - 1)))


/* absolute value without jumps */
#ifndef __cplusplus
#  define  CV_IABS(a)     (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
#else
#  define  CV_IABS(a)     abs(a)
#endif
#define  CV_CMP(a,b)    (((a) > (b)) - ((a) < (b)))
#define  CV_SIGN(a)     CV_CMP((a),0)


CV_INLINE  int  cvRound( double value )                         返回和参数最接近的整数值
{
#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && defined __SSE2__ && !defined __APPLE__)
    __m128d t = _mm_set_sd( value );
    return _mm_cvtsd_si32(t);
#elif defined _MSC_VER && defined _M_IX86
    int t;
    __asm
    {
        fld value;
        fistp t;
    }
    return t;
#elif defined _MSC_VER && defined _M_ARM && defined HAVE_TEGRA_OPTIMIZATION
    TEGRA_ROUND(value);
#elif defined CV_ICC || defined __GNUC__
#  ifdef HAVE_TEGRA_OPTIMIZATION
    TEGRA_ROUND(value);
#  else
    return (int)lrint(value);
#  endif
#else
    double intpart, fractpart;
    fractpart = modf(value, &intpart);
    if ((fabs(fractpart) != 0.5) || ((((int)intpart) % 2) != 0))
        return (int)(value + (value >= 0 ? 0.5 : -0.5));
    else
        return (int)intpart;
#endif
}


#if defined __SSE2__ || (defined _M_IX86_FP && 2 == _M_IX86_FP)
#  include "emmintrin.h"
#endif

//返回不大于参数的最大整数值
CV_INLINE  int  cvFloor( double value )
{
#if defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)
    __m128d t = _mm_set_sd( value );
    int i = _mm_cvtsd_si32(t);
    return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
#elif defined __GNUC__
    int i = (int)value;
    return i - (i > value);
#else
    int i = cvRound(value);
    float diff = (float)(value - i);
    return i - (diff < 0);
#endif
}


//返回不小于参数的最小整数值

CV_INLINE  int  cvCeil( double value )
{
#if defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)
    __m128d t = _mm_set_sd( value );
    int i = _mm_cvtsd_si32(t);
    return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
#elif defined __GNUC__
    int i = (int)value;
    return i + (i < value);
#else
    int i = cvRound(value);
    float diff = (float)(i - value);
    return i + (diff < 0);
#endif
}

//对参数开平方并进行求倒

#define cvInvSqrt(value) ((float)(1./sqrt(value)))

//对参数开平方

#define cvSqrt(value)  ((float)sqrt(value))

//判定是否为合法数
CV_INLINE int cvIsNaN( double value )
{
    Cv64suf ieee754;
    ieee754.f = value;
    return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
           ((unsigned)ieee754.u != 0) > 0x7ff00000;
}



//判定是否为无穷 
CV_INLINE int cvIsInf( double value )
{
    Cv64suf ieee754;
    ieee754.f = value;
    return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
           (unsigned)ieee754.u == 0;
}




/*************** Random number generation *******************/


typedef uint64 CvRNG;


#define CV_RNG_COEFF 4164903690U

//初始化随机数生成器状态
CV_INLINE CvRNG cvRNG( int64 seed CV_DEFAULT(-1))
{
    CvRNG rng = seed ? (uint64)seed : (uint64)(int64)-1;
    return rng;
}

//返回32位随机无符号整型并更新RNG
/* Return random 32-bit unsigned integer: */
CV_INLINE unsigned cvRandInt( CvRNG* rng )
{
    uint64 temp = *rng;
    temp = (uint64)(unsigned)temp*CV_RNG_COEFF + (temp >> 32);
    *rng = temp;
    return (unsigned)temp;
}

//返回浮点型随机数并更新RNG
/* Returns random floating-point number between 0 and 1: */
CV_INLINE double cvRandReal( CvRNG* rng )
{
    return cvRandInt(rng)*2.3283064365386962890625e-10 /* 2^-32 */;
}


/****************************************************************************************\
*                                  Image type (IplImage)                                 *
\****************************************************************************************/


#ifndef HAVE_IPL


/*
 * The following definitions (until #endif)
 * is an extract from IPL headers.
 * Copyright (c) 1995 Intel Corporation.
 */

#define IPL_DEPTH_SIGN 0x80000000


//定义深度位数
#define IPL_DEPTH_1U     1
#define IPL_DEPTH_8U     8
#define IPL_DEPTH_16U   16
#define IPL_DEPTH_32F   32

//定义有符号深度位数
#define IPL_DEPTH_8S  (IPL_DEPTH_SIGN| 8)
#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32)

//定义数据顺序
#define IPL_DATA_ORDER_PIXEL  0
#define IPL_DATA_ORDER_PLANE  1

//定义图像原点位置
#define IPL_ORIGIN_TL 0
#define IPL_ORIGIN_BL 1

//定义扫描线位数
#define IPL_ALIGN_4BYTES   4
#define IPL_ALIGN_8BYTES   8
#define IPL_ALIGN_16BYTES 16
#define IPL_ALIGN_32BYTES 32

//定义扫描线对齐
#define IPL_ALIGN_DWORD   IPL_ALIGN_4BYTES
#define IPL_ALIGN_QWORD   IPL_ALIGN_8BYTES

//定义扫描线宽度状态
#define IPL_BORDER_CONSTANT   0              //扫描线连续
#define IPL_BORDER_REPLICATE  1              //双扫描线
#define IPL_BORDER_REFLECT    2               //带阴影扫描线
#define IPL_BORDER_WRAP       3                  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值