资源描述:
《opencv矩阵操作函数源代码》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、/*////////////////////////////////////////////////////////////////////////CvMat,CvMatND,CvSparceMatandIplImagesupportfunctions//(creation,deletion,copying,retrievingandsettingelementsetc.)////*/#include"_cxcore.h"staticstruct{Cv_iplCreateImageHeadercreateHeader;Cv_iplAllocateIm
2、ageDataallocateData;Cv_iplDeallocatedeallocate;Cv_iplCreateROIcreateROI;Cv_iplCloneImagecloneImage;}CvIPL;//MakesthelibraryusenativeIPLimageallocatorsCV_IMPLvoidcvSetIPLAllocators(Cv_iplCreateImageHeadercreateHeader,Cv_iplAllocateImageDataallocateData,Cv_iplDeallocatedeallocate
3、,Cv_iplCreateROIcreateROI,Cv_iplCloneImagecloneImage){CV_FUNCNAME("cvSetIPLAllocators");__BEGIN__;if(!createHeader
4、
5、!allocateData
6、
7、!deallocate
8、
9、!createROI
10、
11、!cloneImage){if(createHeader
12、
13、allocateData
14、
15、deallocate
16、
17、createROI
18、
19、cloneImage)CV_ERROR(CV_StsBadArg,"Eitherallthepointerss
20、houldbenullor""theyallshouldbenon-null");}CvIPL.createHeader=createHeader;CvIPL.allocateData=allocateData;CvIPL.deallocate=deallocate;CvIPL.createROI=createROI;CvIPL.cloneImage=cloneImage;__END__;}/********************************************************************************
21、*********CvMatcreationandbasicoperations*****************************************************************************************///CreatesCvMatandunderlyingdataCV_IMPLCvMat*cvCreateMat(intheight,intwidth,inttype){CvMat*arr=0;CV_FUNCNAME("cvCreateMat");__BEGIN__;CV_CALL(arr=c
22、vCreateMatHeader(height,width,type));CV_CALL(cvCreateData(arr));__END__;if(cvGetErrStatus()<0)cvReleaseMat(&arr);returnarr;}staticvoidicvCheckHuge(CvMat*arr){if((int64)arr->step*arr->rows>INT_MAX)arr->type&=~CV_MAT_CONT_FLAG;}//CreatesCvMatheaderonlyCV_IMPLCvMat*cvCreateMatHead
23、er(introws,intcols,inttype){CvMat*arr=0;CV_FUNCNAME("cvCreateMatHeader");__BEGIN__;intmin_step;type=CV_MAT_TYPE(type);if(rows<=0
24、
25、cols<=0)CV_ERROR(CV_StsBadSize,"Non-positivewidthorheight");min_step=CV_ELEM_SIZE(type)*cols;if(min_step<=0)CV_ERROR(CV_StsUnsupportedFormat,"Invali
26、dmatrixtype");CV_CALL(arr=(CvMat*)cvAlloc(sizeof(*arr)