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

📄 cxdrawing.cpp

📁 将OpenCV移植到DSP上
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            }            if( (unsigned)y12 < (unsigned)size.height )            {                uchar *tptr = ptr + y12 * step;                if( !fill )                {                    if( x11 >= 0 )                        ICV_PUT_POINT( tptr, x11 );                    if( x12 < size.width )                        ICV_PUT_POINT( tptr, x12 );                }                else                    ICV_HLINE( tptr, x11, x12, color, pix_size );            }            if( x21 < size.width && x22 >= 0 )            {                if( fill )                {                    x21 = MAX( x21, 0 );                    x22 = MIN( x22, size.width - 1 );                }                if( (unsigned)y21 < (unsigned)size.height )                {                    uchar *tptr = ptr + y21 * step;                    if( !fill )                    {                        if( x21 >= 0 )                            ICV_PUT_POINT( tptr, x21 );                        if( x22 < size.width )                            ICV_PUT_POINT( tptr, x22 );                    }                    else                        ICV_HLINE( tptr, x21, x22, color, pix_size );                }                if( (unsigned)y22 < (unsigned)size.height )                {                    uchar *tptr = ptr + y22 * step;                    if( !fill )                    {                        if( x21 >= 0 )                            ICV_PUT_POINT( tptr, x21 );                        if( x22 < size.width )                            ICV_PUT_POINT( tptr, x22 );                    }                    else                        ICV_HLINE( tptr, x21, x22, color, pix_size );                }            }        }        dy++;        err += plus;        plus += 2;        mask = (err <= 0) - 1;        err -= minus & mask;        dx += mask;        minus -= mask & 2;    }    #undef  ICV_PUT_POINT}static voidicvThickLine( CvMat* img, CvPoint p0, CvPoint p1, const void* color,              int thickness, int line_type, int flags, int shift ){    static const double INV_XY_ONE = 1./XY_ONE;    CV_FUNCNAME("icvThickLine");    __BEGIN__;    p0.x <<= XY_SHIFT - shift;    p0.y <<= XY_SHIFT - shift;    p1.x <<= XY_SHIFT - shift;    p1.y <<= XY_SHIFT - shift;    if( thickness <= 1 )    {        if( line_type < CV_AA )        {            if( line_type == 1 || line_type == 4 || shift == 0 )            {                p0.x = (p0.x + (XY_ONE>>1)) >> XY_SHIFT;                p0.y = (p0.y + (XY_ONE>>1)) >> XY_SHIFT;                p1.x = (p1.x + (XY_ONE>>1)) >> XY_SHIFT;                p1.y = (p1.y + (XY_ONE>>1)) >> XY_SHIFT;                icvLine( img, p0, p1, color, line_type );            }            else                icvLine2( img, p0, p1, color );        }        else            icvLineAA( img, p0, p1, color );    }    else    {        CvPoint pt[4], dp = {0,0};        double dx = (p0.x - p1.x)*INV_XY_ONE, dy = (p1.y - p0.y)*INV_XY_ONE;        double r = dx * dx + dy * dy;        int i;        thickness <<= XY_SHIFT - 1;        if( fabs(r) > DBL_EPSILON )        {            r = thickness * cvInvSqrt( (float) r );            dp.x = cvRound( dy * r );            dp.y = cvRound( dx * r );        }        pt[0].x = p0.x + dp.x;        pt[0].y = p0.y + dp.y;        pt[1].x = p0.x - dp.x;        pt[1].y = p0.y - dp.y;        pt[2].x = p1.x - dp.x;        pt[2].y = p1.y - dp.y;        pt[3].x = p1.x + dp.x;        pt[3].y = p1.y + dp.y;        icvFillConvexPoly( img, pt, 4, color, line_type, XY_SHIFT );        for( i = 0; i < 2; i++ )        {            if( flags & (i+1) )            {                if( line_type < CV_AA )                {                    CvPoint center;                    center.x = (p0.x + (XY_ONE>>1)) >> XY_SHIFT;                    center.y = (p0.y + (XY_ONE>>1)) >> XY_SHIFT;                    icvCircle( img, center, thickness >> XY_SHIFT, color, 1 );                 }                else                {                	/*                    icvEllipseEx( img, p0, cvSize(thickness, thickness),                                  0, 0, 360, color, -1, line_type );                    */                    CV_ERROR(CV_StsBadFlag, "antialiased line is not supported.");                                    }            }            p0 = p1;        }    }        __END__;}static voidicvPolyLine( CvMat* img, CvPoint *v, int count, int is_closed,             const void* color, int thickness,             int line_type, int shift ){    CV_FUNCNAME("icvPolyLine");    __BEGIN__;        if( count > 0 )    {        int i = is_closed ? count - 1 : 0;        int flags = 2 + !is_closed;        CvPoint p0;        assert( 0 <= shift && shift <= XY_SHIFT );        assert( img && thickness >= 0 );         assert( v && count >= 0 );        if( !v )            CV_ERROR( CV_StsNullPtr, "" );        p0 = v[i];        for( i = !is_closed; i < count; i++ )        {            CvPoint p = v[i];            icvThickLine( img, p0, p, color, thickness, line_type, flags, shift );            p0 = p;            flags = 2;        }    }    __END__;}/****************************************************************************************\*                              External functions                                        *\****************************************************************************************/CV_IMPL CvScalar cvColorToScalar( double packed_color, int type ){    CvScalar scalar;        if( CV_MAT_DEPTH( type ) == CV_8U )    {        int icolor = cvRound( packed_color );        if( CV_MAT_CN( type ) > 1 )        {            scalar.val[0] = icolor & 255;            scalar.val[1] = (icolor >> 8) & 255;            scalar.val[2] = (icolor >> 16) & 255;            scalar.val[3] = (icolor >> 24) & 255;        }        else        {            scalar.val[0] = CV_CAST_8U( icolor );            scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;        }    }    else if( CV_MAT_DEPTH( type ) == CV_8S )    {        int icolor = cvRound( packed_color );        if( CV_MAT_CN( type ) > 1 )        {            scalar.val[0] = (char)icolor;            scalar.val[1] = (char)(icolor >> 8);            scalar.val[2] = (char)(icolor >> 16);            scalar.val[3] = (char)(icolor >> 24);        }        else        {            scalar.val[0] = CV_CAST_8S( icolor );            scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;        }    }    else    {        int cn = CV_MAT_CN( type );        switch( cn )        {        case 1:            scalar.val[0] = packed_color;            scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;            break;        case 2:            scalar.val[0] = scalar.val[1] = packed_color;            scalar.val[2] = scalar.val[3] = 0;            break;        case 3:            scalar.val[0] = scalar.val[1] = scalar.val[2] = packed_color;            scalar.val[3] = 0;            break;        default:            scalar.val[0] = scalar.val[1] =                scalar.val[2] = scalar.val[3] = packed_color;            break;        }    }    return scalar;}CV_IMPL voidcvLine( void* img, CvPoint pt1, CvPoint pt2, CvScalar color,        int thickness, int line_type, int shift ){    CV_FUNCNAME( "cvLine" );    __BEGIN__;    int coi = 0;    CvMat stub, *mat = (CvMat*)img;    double buf[4];    CV_CALL( mat = cvGetMat( img, &stub, &coi ));    if( line_type == CV_AA && CV_MAT_DEPTH(mat->type) != CV_8U )        line_type = 8;    if( coi != 0 )        CV_ERROR( CV_BadCOI, cvUnsupportedFormat );    if( (unsigned)thickness > 255  )        CV_ERROR( CV_StsOutOfRange, "" );    if( shift < 0 || XY_SHIFT < shift )        CV_ERROR( CV_StsOutOfRange, "shift must be between 0 and 16" );    CV_CALL( cvScalarToRawData( &color, buf, mat->type, 0 ));    icvThickLine( mat, pt1, pt2, buf, thickness, line_type, 3, shift );     __END__;}CV_IMPL voidcvRectangle( void* img, CvPoint pt1, CvPoint pt2,             CvScalar color, int thickness,             int line_type, int shift ){    CvPoint pt[4];    CV_FUNCNAME("cvRectangle");    __BEGIN__;    int coi = 0;    CvMat stub, *mat = (CvMat*)img;    double buf[4];    if( thickness < -1 || thickness > 255 )        CV_ERROR( CV_StsOutOfRange, "" );    CV_CALL( mat = cvGetMat( img, &stub, &coi ));    if( line_type == CV_AA && CV_MAT_DEPTH(mat->type) != CV_8U )        line_type = 8;    if( coi != 0 )        CV_ERROR( CV_BadCOI, cvUnsupportedFormat );    if( shift < 0 || XY_SHIFT < shift )        CV_ERROR( CV_StsOutOfRange, "shift must be between 0 and 16" );    CV_CALL( cvScalarToRawData( &color, buf, mat->type, 0 ));    pt[0] = pt1;    pt[1].x = pt2.x;    pt[1].y = pt1.y;    pt[2] = pt2;    pt[3].x = pt1.x;    pt[3].y = pt2.y;    if( thickness >= 0 )        icvPolyLine( mat, pt, 4, 1, buf, thickness, line_type, shift );    else        icvFillConvexPoly( mat, pt, 4, buf, line_type, shift );    __END__;}CV_IMPL voidcvFillConvexPoly( void *img, CvPoint *pts, int npts, CvScalar color, int line_type, int shift ){    CV_FUNCNAME( "cvFillConvexPoly" );    __BEGIN__;    int coi = 0;    CvMat stub, *mat = (CvMat*)img;    double buf[4];    CV_CALL( mat = cvGetMat( mat, &stub, &coi ));    if( line_type == CV_AA && CV_MAT_DEPTH(mat->type) != CV_8U )        line_type = 8;    if( coi != 0 )        CV_ERROR( CV_BadCOI, cvUnsupportedFormat );    if( !pts )        CV_ERROR( CV_StsNullPtr, "" );    if( npts <= 0 )        CV_ERROR( CV_StsOutOfRange, "" );    if( shift < 0 || XY_SHIFT < shift )        CV_ERROR( CV_StsOutOfRange, "shift must be between 0 and 16" );    CV_CALL( cvScalarToRawData( &color, buf, mat->type, 0 ));    icvFillConvexPoly( mat, pts, npts, buf, line_type, shift );    __END__;}CV_IMPL voidcvPolyLine( void *img, CvPoint **pts, int *npts,            int contours, int closed, CvScalar color,            int thickness, int line_type, int shift ){    CV_FUNCNAME( "cvPolyLine" );    __BEGIN__;    int coi = 0, i;

⌨️ 快捷键说明

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