OpenCV经典代码

///

//           1            //

#define CV_MAJOR_VERSION1   2

#define CV_MINOR_VERSION1    0

#define CV_SUBMINOR_VERSION1 0

#define CVAUX_STR_EXP1(__A)  #__A

#define CVAUX_STR1(__A)      CVAUX_STR_EXP1(__A)

#define CV_VERSION1          CVAUX_STR1(CV_MAJOR_VERSION1) "." CVAUX_STR1(CV_MINOR_VERSION1) "." CVAUX_STR1(CV_SUBMINOR_VERSION1)

//            2           //

template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))

{

    //当n=2,4,8,16,32,64,...时才能真正的对齐

    return (_Tp*)(((size_t)ptr + n-1) & -n);

}

//            3           //

void error( const Exception& exc )

{

    if (customErrorCallback != 0)

        customErrorCallback(exc.code, exc.func.c_str(), exc.err.c_str(),

                            exc.file.c_str(), exc.line, customErrorCallbackData);

    else

    {

        const char* errorStr = cvErrorStr(exc.code);

        char buf[1 << 16];

        sprintf( buf, "OpenCV Error: %s (%s) in %s, file %s, line %d",

            errorStr, exc.err.c_str(), exc.func.size() > 0 ?

            exc.func.c_str() : "unknown function", exc.file.c_str(), exc.line );

        fprintf( stderr, "%s\n", buf );

        fflush( stderr );

    }

    if(breakOnError)

    {

        static volatile int* p = 0;//不懂为什么要用volatile变量 也不懂这里究竟做了什么工作

        *p = 0;

    }

    throw exc;

}

//            4           //

class AException

{

public:

    AException() { code = 0; line = 0; }

    AException(int _code, const string& _err, const string& _func, const string& _file, int _line)

        : code(_code), err(_err), func(_func), file(_file), line(_line) {}

    AException(const AException& exc)

        : code(exc.code), err(exc.err), func(exc.func), file(exc.file), line(exc.line) {}

    AException& operator = (const AException& exc)

    {

        if( this != &exc )

        {

            code = exc.code; err = exc.err; func = exc.func; file = exc.file; line = exc.line;

        }

        return *this;

    }

    int code;

    string err;

    string func;

    string file;

    int line;

};

int _tmain(int argc, _TCHAR* argv[])

{

    string x = "x123567";

    AException* an = new AException(3,"异常","_tmain",__FILE__,__LINE__);

    try

    {

        throw *an;

    }

    catch (AException e)//catch中的类型与其中的异常必需一致才能截获异常,*an  与 e的类型是一样的

    {

        x="e";

    }

    const char* c = x.c_str();

    printf("%s",c);

    int b;

    cin >>b;

    return 0;

}

close

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_38220914

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值