Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

opencv

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.

like image 641
penelope Avatar asked Aug 08 '11 16:08

penelope


1 Answers

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.

like image 134
robermorales Avatar answered Oct 23 '22 15:10

robermorales