在 CvSeq 中推送 CvMat 类型的元素

发布于 2025-01-03 21:18:01 字数 1459 浏览 0 评论 0原文

我在这里尝试创建一个将 CvMat 作为其元素的序列。我编写的代码与“

  for(CvSeq *c = first_contour;c!=NULL;c = c->h_next)
   {
    //New Seq created for each component seq in first_contour
    CvSeq * newSeq = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvMat),storage);

    cvDrawContours(iOriginal,c,red,green,0,2,8);
    //Printing the contour no.
    printf("Contour == %d\n",nTmp);

    cvShowImage("Countour Information",iOriginal);

    //Printing the total no of elements in each sequence
    printf("%d Elements",c->total);

    //Creating a matrix with the dimension (total by 2)
    CvMat * matBoundary = cvCreateMat(c->total,2,CV_64FC1);

    //Iterating thru each seq to access its elements and setting it to matrix      matBoundary
    for(int i =0 ;i<c->total;i++)
    {
        CvPoint * p = CV_GET_SEQ_ELEM(CvPoint,c,i);
        cvmSet(matBoundary,i,0,p->x);
        cvmSet(matBoundary,i,1,p->y);
        printf("(%d,%d)\n",p->x,p->y);
    }
    //Pushing new matrix's address in newSeq
    cvSeqPush(newSeq,&matBoundary);

    //Checking the contents of boundary mat
    //for(CvSeq * s = boundarySeq;s!=NULL;s = s->h_next)
    //{
        CvMat * mat = CV_GET_SEQ_ELEM(CvMat,newSeq,1);
        for(int i = 0;i<mat->rows;i++)
        {   
            int x = cvmGet(mat,i,0);
            int y = cvmGet(mat,i,0);
            printf("x=%d y=%d",x,y);
        }

任何人都可以告诉我问题是什么”相同,因为我在“newSeq”中没有得到任何结果。

I am here trying to create a sequence which holds the CvMat as its element.I wrote the code for the same as

  for(CvSeq *c = first_contour;c!=NULL;c = c->h_next)
   {
    //New Seq created for each component seq in first_contour
    CvSeq * newSeq = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvMat),storage);

    cvDrawContours(iOriginal,c,red,green,0,2,8);
    //Printing the contour no.
    printf("Contour == %d\n",nTmp);

    cvShowImage("Countour Information",iOriginal);

    //Printing the total no of elements in each sequence
    printf("%d Elements",c->total);

    //Creating a matrix with the dimension (total by 2)
    CvMat * matBoundary = cvCreateMat(c->total,2,CV_64FC1);

    //Iterating thru each seq to access its elements and setting it to matrix      matBoundary
    for(int i =0 ;i<c->total;i++)
    {
        CvPoint * p = CV_GET_SEQ_ELEM(CvPoint,c,i);
        cvmSet(matBoundary,i,0,p->x);
        cvmSet(matBoundary,i,1,p->y);
        printf("(%d,%d)\n",p->x,p->y);
    }
    //Pushing new matrix's address in newSeq
    cvSeqPush(newSeq,&matBoundary);

    //Checking the contents of boundary mat
    //for(CvSeq * s = boundarySeq;s!=NULL;s = s->h_next)
    //{
        CvMat * mat = CV_GET_SEQ_ELEM(CvMat,newSeq,1);
        for(int i = 0;i<mat->rows;i++)
        {   
            int x = cvmGet(mat,i,0);
            int y = cvmGet(mat,i,0);
            printf("x=%d y=%d",x,y);
        }

Can Anybody tell me what is the problem because I am getting nothing in 'newSeq'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文