开发者

OpenCV sequences -- how to create a sequence of point pairs?

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); 

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? :/

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... :(

Thank you all very much for your help!

EDIT: found the solution.

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);

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.


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);

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜