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

📄 cxarray.cpp.svn-base

📁 这是于老师移植到dsp的源码
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
////////////////////////////////////////////////////////////////////////////////////////////  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.//////                 License For Embedded Computer Vision Library//// Copyright (c) 2008, EMCV Project,// Copyright (c) 2000-2007, 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:////    * Redistributions of source code must retain the above copyright notice, //      this list of conditions and the following disclaimer.//    * Redistributions 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.//    * Neither the name of the copyright holders nor the names of their contributors //      may 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 COPYRIGHT OWNER 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.//// Contributors://    * Shiqi Yu (Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences)#include "_cxcore.h"static IplROI* icvCreateROI( int coi, int xOffset, int yOffset, int width, int height ){    IplROI *roi = 0;    CV_FUNCNAME( "icvCreateROI" );    __BEGIN__;    CV_CALL( roi = (IplROI*)cvAlloc( sizeof(*roi)));    roi->coi = coi;    roi->xOffset = xOffset;    roi->yOffset = yOffset;    roi->width = width;    roi->height = height;    __END__;    return roi;}static  voidicvGetColorModel( int nchannels, char** colorModel, char** channelSeq ){    static char* tab[][2] =    {        {"GRAY", "GRAY"},        {"",""},        {"RGB","BGR"},        {"RGB","BGRA"}    };    nchannels--;    *colorModel = *channelSeq = "";    if( (unsigned)nchannels <= 3 )    {        *colorModel = tab[nchannels][0];        *channelSeq = tab[nchannels][1];    }}// create IplImage headerCV_IMPL IplImage *cvCreateImageHeader( CvSize size, int depth, int channels ){    IplImage *img = 0;    CV_FUNCNAME( "cvCreateImageHeader" );    __BEGIN__;    CV_CALL( img = (IplImage *)cvAlloc( sizeof( *img )));    CV_CALL( cvInitImageHeader( img, size, depth, channels, IPL_ORIGIN_TL,                                    CV_DEFAULT_IMAGE_ROW_ALIGN ));    __END__;    if( cvGetErrStatus() < 0 && img )        cvReleaseImageHeader( &img );    return img;}// create IplImage header and allocate underlying dataCV_IMPL IplImage *cvCreateImage( CvSize size, int depth, int channels ){    IplImage *img = 0;    CV_FUNCNAME( "cvCreateImage" );    __BEGIN__;    CV_CALL( img = cvCreateImageHeader( size, depth, channels ));    assert( img );    CV_CALL( cvCreateData( img ));    __END__;    if( cvGetErrStatus() < 0 )        cvReleaseImage( &img );    return img;}// initalize IplImage header, allocated by the userCV_IMPL IplImage*cvInitImageHeader( IplImage * image, CvSize size, int depth,                   int channels, int origin, int align ){    IplImage* result = 0;    CV_FUNCNAME( "cvInitImageHeader" );    __BEGIN__;    char *colorModel, *channelSeq;    if( !image )        CV_ERROR( CV_HeaderIsNull, "null pointer to header" );    memset( image, 0, sizeof( *image ));    image->nSize = sizeof( *image );    CV_CALL( icvGetColorModel( channels, &colorModel, &channelSeq ));    strncpy( image->colorModel, colorModel, 4 );    strncpy( image->channelSeq, channelSeq, 4 );    if( size.width < 0 || size.height < 0 )        CV_ERROR( CV_BadROISize, "Bad input roi" );    if( (depth != (int)IPL_DEPTH_1U && depth != (int)IPL_DEPTH_8U &&         depth != (int)IPL_DEPTH_8S && depth != (int)IPL_DEPTH_16U &&         depth != (int)IPL_DEPTH_16S && depth != (int)IPL_DEPTH_32S &&         depth != (int)IPL_DEPTH_32F && depth != (int)IPL_DEPTH_64F) ||         channels < 0 )        CV_ERROR( CV_BadDepth, "Unsupported format" );    if( origin != CV_ORIGIN_BL && origin != CV_ORIGIN_TL )        CV_ERROR( CV_BadOrigin, "Bad input origin" );    if( align != 4 && align != 8 )        CV_ERROR( CV_BadAlign, "Bad input align" );    image->width = size.width;    image->height = size.height;    if( image->roi )    {        image->roi->coi = 0;        image->roi->xOffset = image->roi->yOffset = 0;        image->roi->width = size.width;        image->roi->height = size.height;    }    image->nChannels = MAX( channels, 1 );    image->depth = depth;    image->align = align;    image->widthStep = (((image->width * image->nChannels *         (image->depth & ~IPL_DEPTH_SIGN) + 7)/8)+ align - 1) & (~(align - 1));    image->origin = origin;    image->imageSize = image->widthStep * image->height;    result = image;    __END__;    return result;}CV_IMPL voidcvReleaseImageHeader( IplImage** image ){    CV_FUNCNAME( "cvReleaseImageHeader" );    __BEGIN__;    if( !image )        CV_ERROR( CV_StsNullPtr, "" );    if( *image )    {        IplImage* img = *image;        *image = 0;                cvFree( &img->roi );        cvFree( &img );    }    __END__;}CV_IMPL voidcvReleaseImage( IplImage ** image ){    CV_FUNCNAME( "cvReleaseImage" );    __BEGIN__    if( !image )        CV_ERROR( CV_StsNullPtr, "" );    if( *image )    {        IplImage* img = *image;        *image = 0;                cvReleaseData( img );        cvReleaseImageHeader( &img );    }    __END__;}/****************************************************************************************\*                               CvMat creation and basic operations                      *\****************************************************************************************/// Creates CvMat and underlying dataCV_IMPL CvMat*cvCreateMat( int height, int width, int type ){    CvMat* arr = 0;    CV_FUNCNAME( "cvCreateMat" );        __BEGIN__;    CV_CALL( arr = cvCreateMatHeader( height, width, type ));    CV_CALL( cvCreateData( arr ));    __END__;    if( cvGetErrStatus() < 0 )        cvReleaseMat( &arr );    return arr;}static void icvCheckHuge( CvMat* arr ){    if( (int)arr->step*arr->rows > INT_MAX )        arr->type &= ~CV_MAT_CONT_FLAG;}// Creates CvMat header onlyCV_IMPL CvMat*cvCreateMatHeader( int rows, int cols, int type ){    CvMat* arr = 0;        CV_FUNCNAME( "cvCreateMatHeader" );    __BEGIN__;    int min_step;    type = CV_MAT_TYPE(type);    if( rows <= 0 || cols <= 0 )        CV_ERROR( CV_StsBadSize, "Non-positive width or height" );    min_step = CV_ELEM_SIZE(type)*cols;    if( min_step <= 0 )        CV_ERROR( CV_StsUnsupportedFormat, "Invalid matrix type" );    CV_CALL( arr = (CvMat*)cvAlloc( sizeof(*arr)));    arr->step = rows == 1 ? 0 : cvAlign(min_step, CV_DEFAULT_MAT_ROW_ALIGN);    arr->type = CV_MAT_MAGIC_VAL | type |                (arr->step == 0 || arr->step == min_step ? CV_MAT_CONT_FLAG : 0);    arr->rows = rows;    arr->cols = cols;    arr->data.ptr = 0;    arr->refcount = 0;    arr->hdr_refcount = 1;    icvCheckHuge( arr );    __END__;    if( cvGetErrStatus() < 0 )        cvReleaseMat( &arr );    return arr;}// Initializes CvMat header, allocated by the userCV_IMPL CvMat*cvInitMatHeader( CvMat* arr, int rows, int cols,                 int type, void* data, int step ){    CV_FUNCNAME( "cvInitMatHeader" );        __BEGIN__;    int mask, pix_size, min_step;    if( !arr )        CV_ERROR_FROM_CODE( CV_StsNullPtr );    if( (unsigned)CV_MAT_DEPTH(type) > CV_DEPTH_MAX )        CV_ERROR_FROM_CODE( CV_BadNumChannels );    if( rows <= 0 || cols <= 0 )        CV_ERROR( CV_StsBadSize, "Non-positive cols or rows" );     type = CV_MAT_TYPE( type );    arr->type = type | CV_MAT_MAGIC_VAL;    arr->rows = rows;    arr->cols = cols;    arr->data.ptr = (uchar*)data;    arr->refcount = 0;    arr->hdr_refcount = 0;    mask = (arr->rows <= 1) - 1;    pix_size = CV_ELEM_SIZE(type);    min_step = arr->cols*pix_size & mask;    if( step != CV_AUTOSTEP && step != 0 )    {        if( step < min_step )            CV_ERROR_FROM_CODE( CV_BadStep );        arr->step = step & mask;    }    else    {        arr->step = min_step;    }    arr->type = CV_MAT_MAGIC_VAL | type |                (arr->step == min_step ? CV_MAT_CONT_FLAG : 0);    icvCheckHuge( arr );    __END__;    return arr;}// Deallocates the CvMat structure and underlying dataCV_IMPL voidcvReleaseMat( CvMat** array ){    CV_FUNCNAME( "cvReleaseMat" );        __BEGIN__;    if( !array )        CV_ERROR_FROM_CODE( CV_HeaderIsNull );    if( *array )    {        CvMat* arr = *array;                if( !CV_IS_MAT_HDR(arr) && !CV_IS_MATND_HDR(arr) )            CV_ERROR_FROM_CODE( CV_StsBadFlag );        *array = 0;        cvDecRefData( arr );        cvFree( &arr );    }    __END__;}// Creates a copy of matrixCV_IMPL CvMat*cvCloneMat( const CvMat* src ){    CvMat* dst = 0;    CV_FUNCNAME( "cvCloneMat" );    __BEGIN__;    if( !CV_IS_MAT_HDR( src ))        CV_ERROR( CV_StsBadArg, "Bad CvMat header" );    CV_CALL( dst = cvCreateMatHeader( src->rows, src->cols, src->type ));    if( src->data.ptr )    {        CV_CALL( cvCreateData( dst ));        CV_CALL( cvCopy( src, dst ));    }    __END__;    return dst;}// Deallocates array's dataCV_IMPL voidcvReleaseData( CvArr* arr ){    CV_FUNCNAME( "cvReleaseData" );        __BEGIN__;    if( CV_IS_MAT_HDR( arr ) || CV_IS_MATND_HDR( arr ))    {        CvMat* mat = (CvMat*)arr;        cvDecRefData( mat );    }    else if( CV_IS_IMAGE_HDR( arr ))    {        IplImage* img = (IplImage*)arr;        char* ptr = img->imageDataOrigin;        img->imageData = img->imageDataOrigin = 0;        cvFree( &ptr );    }    else    {        CV_ERROR( CV_StsBadArg, "unrecognized or unsupported array type" );    }    __END__;}/****************************************************************************************\*                          Common for multiple array types operations                    *\****************************************************************************************/// Allocates underlying array dataCV_IMPL voidcvCreateData( CvArr* arr ){    CV_FUNCNAME( "cvCreateData" );        __BEGIN__;    if( CV_IS_MAT_HDR( arr ))    {        size_t step, total_size;        CvMat* mat = (CvMat*)arr;        step = mat->step;        if( mat->data.ptr != 0 )            CV_ERROR( CV_StsError, "Data is already allocated" );        if( step == 0 )            step = CV_ELEM_SIZE(mat->type)*mat->cols;        total_size = step*mat->rows + sizeof(int) + CV_MALLOC_ALIGN;        CV_CALL( mat->refcount = (int*)cvAlloc( (size_t)total_size ));        mat->data.ptr = (uchar*)cvAlignPtr( mat->refcount + 1, CV_MALLOC_ALIGN );        *mat->refcount = 1;    }    else if( CV_IS_IMAGE_HDR(arr))    {        IplImage* img = (IplImage*)arr;        if( img->imageData != 0 )            CV_ERROR( CV_StsError, "Data is already allocated" );        CV_CALL( img->imageData = img->imageDataOrigin =                     (char*)cvAlloc( (size_t)img->imageSize ));    }    else if( CV_IS_MATND_HDR( arr ))    {        CvMatND* mat = (CvMatND*)arr;        int i;        size_t total_size = CV_ELEM_SIZE(mat->type);        if( mat->data.ptr != 0 )            CV_ERROR( CV_StsError, "Data is already allocated" );        if( CV_IS_MAT_CONT( mat->type ))        {            total_size = (size_t)mat->dim[0].size*(mat->dim[0].step != 0 ?                         mat->dim[0].step : total_size);        }        else        {            for( i = mat->dims - 1; i >= 0; i-- )            {                size_t size = (size_t)mat->dim[i].step*mat->dim[i].size;                if( total_size < size )                    total_size = size;            }        }                CV_CALL( mat->refcount = (int*)cvAlloc( total_size +                                        sizeof(int) + CV_MALLOC_ALIGN ));        mat->data.ptr = (uchar*)cvAlignPtr( mat->refcount + 1, CV_MALLOC_ALIGN );        *mat->refcount = 1;    }

⌨️ 快捷键说明

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