700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > C语言中cvpoint后运行出错 c++ - 使用cvCreateSeq时出现未处理的异常 - 堆栈内存溢出...

C语言中cvpoint后运行出错 c++ - 使用cvCreateSeq时出现未处理的异常 - 堆栈内存溢出...

时间:2023-08-25 17:28:27

相关推荐

C语言中cvpoint后运行出错 c++ - 使用cvCreateSeq时出现未处理的异常 - 堆栈内存溢出...

我正在使用cvCreateSeq函数在opencv中创建序列,而调试时会发生异常,例如“未处理的异常在0x7c812afb”。我使用C语言进行编码,并且IDE是Visual C ++ Express Edition。

谁能告诉我为什么发生此异常。

谢谢,

代码是:-

void main()

{

char * file = "D:\\testImage.jpg";

temp(file);

}

void computeCococlust(char * filepath)

{

CvMemStorage * storageContour = NULL;

CvSeq * first_contour = NULL;

IplImage * iOriginal = NULL;

/*Load the image*/

iOriginal = cvLoadImage(filepath,CV_LOAD_IMAGE_UNCHANGED);

/*Load a Grayscale image*/

IplImage * iGray = cvLoadImage(filepath,CV_LOAD_IMAGE_GRAYSCALE);

/*Show original image in a window named 'Original Image'*/

fnShowImageInWindow("Original Image",iOriginal);

/*Show graylevel image in a window named 'GrayLevel Image'*/

fnShowImageInWindow("GrayLevel Image",iGray);

fnReleasingMemoryOfWindow("GrayLevel Image",iGray);

/*------Getting single channel image as red green blue from RGB iOriginal----------*/

IplImage *iRed = cvCreateImage(cvGetSize(iOriginal), iOriginal->depth, 1);

IplImage *iGreen = cvCreateImage(cvGetSize(iOriginal), iOriginal->depth, 1);

IplImage *iBlue = cvCreateImage(cvGetSize(iOriginal), iOriginal->depth, 1);

cvSplit(iOriginal, iBlue, iGreen, iRed, NULL);

/*Show iRed,iGreen,iBlue in window*/

fnShowImageInWindow("Red Component Image",iRed);

fnShowImageInWindow("Green Component Image",iGreen);

fnShowImageInWindow("Blue Component Image",iBlue);

/*---------------------------------------------------------------------------------*/

/*--------Perform canny edge detection--------------------------------------------*/

/*For Red Component*/

IplImage * eRed = cvCreateImage(cvGetSize(iRed),iRed->depth,1);

cvCanny(iRed,eRed,10,100,3);

/*For Green Component*/

IplImage * eGreen = cvCreateImage(cvGetSize(iGreen),iGreen->depth,1);

cvCanny(iGreen,eGreen,10,100,3);

/*For Blue Component*/

IplImage * eBlue = cvCreateImage(cvGetSize(iBlue),iBlue->depth,1);

cvCanny(iBlue,eBlue,10,100,3);

/*-----Show eRed,eGreen,eBlue in window------------------------------------------*/

fnShowImageInWindow("Red Component Edge Image",eRed);

fnShowImageInWindow("Green Component Edge Image",eGreen);

fnShowImageInWindow("Blue Component Edge Image",eBlue);

/*-------------------------------------------------------------------------------*/

/*-----Performing union of edge images by using cvMax-----------------------------*/

IplImage * iMaxTmp = cvCreateImage(cvGetSize(iOriginal),iOriginal->depth,1);

IplImage * iUnionImage = cvCreateImage(cvGetSize(iOriginal),iOriginal->depth,1);

cvMax(eRed,eGreen,iMaxTmp);

cvMax(iMaxTmp,eBlue,iUnionImage);

fnShowImageInWindow("union of all images",iUnionImage);

/*-------------------------------------------------------------------------------*/

/*----Getting the boundary pixel of each connected component---------------------*/

storageContour = cvCreateMemStorage(0);

int numCountour = cvFindContours(iUnionImage,storageContour,&first_contour,sizeof(CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_NONE);

printf("Total countours detected %d",numCountour);

CvMemStorage * storage = cvCreateMemStorage(0);

/*-------------------------------------------------------------------------------*/

/*----Smoothing the contour------------------------------------------------------*/

for(CvSeq * seqSmooth = first_contour;seqSmooth!=NULL;seqSmooth = seqSmooth->h_next)

{

CvSeq * newSeq = cvCreateSeq(CV_32FC1,sizeof(CvSeq),sizeof(CvPoint),storage);

for(int i =3 ; itotal-2 ;i++)

{

CvPoint * ps1 = CV_GET_SEQ_ELEM(CvPoint,seqSmooth,i-2);

CvPoint * ps2 = CV_GET_SEQ_ELEM(CvPoint,seqSmooth,i-1);

CvPoint * ps3 = CV_GET_SEQ_ELEM(CvPoint,seqSmooth,i);

CvPoint * ps4 = CV_GET_SEQ_ELEM(CvPoint,seqSmooth,i+1);

CvPoint * ps5 = CV_GET_SEQ_ELEM(CvPoint,seqSmooth,i+2);

CvPoint newPoint = cvPoint((ps1->x + ps2->x + ps3->x + ps4->x + ps5->x)/5,(ps1->y + ps2->y + ps3->y + ps4->y + ps5->y)/5);

cvSeqPush(newSeq,&newPoint);

}

if(storageContour->bottom->prev != NULL)

{

CvMemBlock * oldNext = storageContour->bottom->next;

CvMemBlock * oldPrev = storageContour->bottom->prev;

storageContour->bottom = newSeq->storage->bottom;

storageContour->bottom->next = oldNext;

storageContour->bottom->prev = oldPrev;

}

else

{

CvMemBlock * oldNext = storageContour->bottom->next;

storageContour->bottom = newSeq->storage->bottom;

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。