在 CvSeq 中推送 CvMat 类型的元素
我在这里尝试创建一个将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论