OpenCV序列-如何创建点对序列? [英] OpenCV sequences -- how to create a sequence of point pairs?

查看:115
本文介绍了OpenCV序列-如何创建点对序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OpenCV中创建一个空序列(CvSeq),其结构类似于例如cvHoughLines2(在CV_HOUGH_PROBABILISTIC中使用时)返回的序列-点对的序列

I'm trying to create an empty sequence (CvSeq) in OpenCV similar in structure to the one returned by, for example, cvHoughLines2 (when used in CV_HOUGH_PROBABILISTIC) - a sequence of point pairs.

我找到了一种方法来制作(未连接的)点序列(我希望这对于点序列是正确的):

I have found a way to make a sequence of (unconnected) points (I hope this is correct for a point sequence):

CvMemStorage *memStorage = cvCreateMemStorage(0);
CvSeq* seq = cvCreateSeq(
             CV_SEQ_FLAG_SIMPLE | CV_SEQ_KIND_SET | CV_SEQ_ELTYPE_POINT,
             sizeof(CvSeq), sizeof(CvPoint), memStorage); 

,但查看可用于创建CvSeq的标志,我找不到我可以用来构造其元素为点对的序列的任何内容.我想以访问Hough变换所得到的行的相同方式来访问所创建序列的元素:

but looking at the flags available for creating CvSeq I can not find anything I could use to construct a sequence whose elements would be point pairs. I would like to access the elements of my created sequence in the same way I access the lines I get from the Hough Transform:

for (int i=0; i < mylines->total; ++i){
    CvPoint *line = (CvPoint *)cvGetSeqElem(mylines, i);

    ...

    ... line[0].x ...
    ... line[1].y ... 

    ...
}

此外,我将如何按这样的顺序插入元素? :/

Also, how would I insert elements in such a sequence? :/

该问题的原因是,我已经有一个相当复杂的函数要对cvHoughLines2()函数返回的行的CvSeq行进行操作,并且我想在图片中创建的任意行上使用它(测试目的等).我到处都在寻找类似问题的答案,但找不到任何东西...:(

The reason for the question is that I already have quite a complex function operating on a CvSeq of lines returned by a cvHoughLines2() function, and I would like to use it on some arbitrary lines I would create in the picture (testing purposes, etc...). I have looked all over for an answer to a similar question, but couldn't find anything... :(

非常感谢大家的帮助!

看起来唯一需要做的事情就是完全省略这些标志,这表明您将不会使用任何预定义的类型(例如点),而只需给出正确的序列部分大小即可:

Looks like the only thing that needs to be done is to omit the flags completely, indicating that you will not be using any of the predefined types (e.g points), and just give the right size of the sequence component:

CvMemStorage *memStorage = cvCreateMemStorage(0);
CvSeq* seq = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint)*2, memStorage);

然后我可以通过将指向2点数组的指针传递给push函数来添加到存储中:

I can than add to the storage by passing the pointer to a 2-point array to the push function:

CvPoint points[2];
... (initialize the points) ...
cvSeqPush(seq, &points);

这样,我可以像访问霍夫变换的输出一样访问序列.

This way I can access the sequence in the same way I accessed the output of the Hough Transform.

推荐答案

在寻求解决方案20分钟以寻求帮助后,我阅读了整个问题并找到了解决方案编辑. 复制并粘贴,以使此问题摆脱未回答.

After 20 minutes searching for a solution in order to help, I read the entire question and found a solution edit. Copy and paste, in order to get this question out of unanswered.

看起来唯一需要做的事情是完全省略标志,表明您将不会使用任何预定义的类型(例如,磅),而只需提供正确的大小序列组成部分:

Looks like the only thing that needs to be done is to omit the flags completely, indicating that you will not be using any of the predefined types (e.g points), and just give the right size of the sequence component:

CvMemStorage *memStorage = cvCreateMemStorage(0);
CvSeq* seq = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint)*2, memStorage);

然后我可以通过将指向2点数组的指针传递给push函数来添加到存储中:

I can than add to the storage by passing the pointer to a 2-point array to the push function:

CvPoint points[2];
... (initialize the points) ...
cvSeqPush(seq, &points);

这样,我可以像访问霍夫变换的输出一样访问序列.

This way I can access the sequence in the same way I accessed the output of the Hough Transform.

这篇关于OpenCV序列-如何创建点对序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆