title: OpenCV sequences -- how to create a sequence of point pairs?
body: <p>I'm trying to create an empty sequence (<code>CvSeq</code>) in <code>OpenCV</code> similar in structure to the one returned by, for example, <code>cvHoughLines2</code> (when used in <code>CV_HOUGH_PROBABILISTIC</code>) - a sequence of point pairs.</p>
  <p>I have found a way to make a sequence of (unconnected) points (I hope this is correct for a point sequence):</p>
  <pre><code>CvMemStorage *memStorage = cvCreateMemStorage(0);
  CvSeq* seq = cvCreateSeq(
               CV_SEQ_FLAG_SIMPLE | CV_SEQ_KIND_SET | CV_SEQ_ELTYPE_POINT,
               sizeof(CvSeq), sizeof(CvPoint), memStorage); 
  </code></pre>
  <p>but looking at the flags available for creating <code>CvSeq</code> 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:</p>
  <pre><code>for (int i=0; i &lt; mylines-&gt;total; ++i){
      CvPoint *line = (CvPoint *)cvGetSeqElem(mylines, i);
  
      ...
  
      ... line[0].x ...
      ... line[1].y ... 
  
      ...
  }
  </code></pre>
  <p>Also, how would I insert elements in such a sequence? :/</p>
  <p>The reason for the question is that I already have quite a complex function operating on a <code>CvSeq</code> of lines returned by a <code>cvHoughLines2()</code> 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... :(</p>
  <p>Thank you all very much for your help!</p>
  <h2>EDIT: found the solution.</h2>
  <p>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:</p>
  <pre><code>CvMemStorage *memStorage = cvCreateMemStorage(0);
  CvSeq* seq = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvPoint)*2, memStorage);
  </code></pre>
  <p>I can than add to the storage by passing the pointer to a 2-point array to the <code>push</code> function:</p>
  <pre><code>CvPoint points[2];
  ... (initialize the points) ...
  cvSeqPush(seq, &amp;points);
  </code></pre>
  <p>This way I can access the sequence in the same way I accessed the output of the Hough Transform.</p>