使用cvCreateSeq时出现未处理的异常

时间:2012-01-17 11:50:52

标签: c++ c opencv

我正在使用cvCreateSeq函数在opencv中创建一个序列,而调试异常则发​​生在'0x7c812afb'处的未处理异常。我在C编码,IDE是visual c ++ 2010 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 ; i<seqSmooth->total-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;
    }
}

0 个答案:

没有答案