<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:12pt"><div>I do apoligize if i added to much code on this....it just seems difficult to explain without showing all the code involve. pls let me know if this isnt worded right to community guidelines and i'll edit it....pls be precise so i know what to change..<br><br>here is how the struct CvSeq is defined<br><br><br>#define CV_TREE_NODE_FIELDS(node_type)                               \<br>    int       flags;             /* Miscellaneous flags.     */      \<br>    int      
 header_size;       /* Size of sequence header. */      \<br>    struct    node_type* h_prev; /* Previous sequence.       */      \<br>    struct    node_type* h_next; /* Next sequence.           */      \<br>    struct    node_type* v_prev; /* 2nd previous sequence.   */      \<br>    struct    node_type* v_next  /* 2nd next sequence.       */<br><br>/*<br>   Read/Write sequence.<br>   Elements can be dynamically inserted to or deleted from the sequence.<br>*/<br>#define
 CV_SEQUENCE_FIELDS()                                              \<br>    CV_TREE_NODE_FIELDS(CvSeq);                                           \<br>    int       total;          /* Total number of elements.            */  \<br>    int       elem_size;      /* Size of sequence element in
 bytes.   */  \<br>    schar*    block_max;      /* Maximal bound of the last block.     */  \<br>    schar*    ptr;            /* Current write pointer.               */  \<br>    int       delta_elems;    /* Grow seq this many at a time.        */  \<br>    CvMemStorage* storage;    /* Where the seq is stored.             */  \<br>    CvSeqBlock* free_blocks;  /* Free blocks
 list.                    */  \<br>    CvSeqBlock* first;        /* Pointer to the first sequence block. */<br><br>typedef struct CvSeq<br>{<br>    CV_SEQUENCE_FIELDS()<br>}<br>CvSeq;</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier
 New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;">and here is how i ended up wrapping it.<br><br><br><br>;; (cffi:foreign-type-size '(:struct cv-seq)) = 96<br>(cffi:defcstruct cv-seq<br>    (flags :int)<br>    (header-size :int)<br>    (h-prev :pointer)<br>    (h-next :pointer)<br>    (v-prev :pointer)<br>    (v-next :pointer)<br>    (total :int)<br>    (elem-size :int)<br>    (block-max :pointer)<br>    (ptr :pointer)<br>    (delta-elems :int)<br>    (storage :pointer)<br>    (free-blocks :pointer)<br>    (first
 :pointer))<br><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;">I was curious what to do with the h_next h_prev and v_prev and v_next, they seem to be recursive and they are not working or i am not using them right normally when a struct contains a  member like  CvMemStorage* storage; I wrap it like this (:pointer (:struct cv-mem-storage)) and it works but h_next i/e seems to point back to itself<br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier
 New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br>this is the way the h_next struct member works in c.  in the below code while contours is not null it iterates though a while loop and through every iteration it sets the variable contours to the next pointer stored in h_next which is set by the cvFindContours function. the cvFindContours fubction in c adds a pointer to the h_next member of the CvSeq struct for every item in the picture it finds...pls see below link for more details and example picture (trying 2 keep this short)  ...  <br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div
 style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;">the code i got the below snippet from is the first program on this page.....http://opencv-srf.blogspot.com/2011/09/object-detection-tracking-using-contours.html  (i broke it down so it would be easier to understand)<br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br><br>int main()<br>{<br><br>IplImage* img =  cvLoadImage("/home/w/quicklisp/dists/quicklisp/software/cl-opencv-master/images/FindingContours.png");<br>//converting the original image into grayscale<br>IplImage* imgGrayScale =
 cvCreateImage(cvGetSize(img), 8, 1); <br>CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours<br> CvSeq* contours= cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint), storage);<br>//finding all contours in the image<br>cvFindContours(imgGrayScale, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));<br>//iterating through each contour<br>while(contours)<br>{cout << "contours = " << endl << " " << contours << endl << endl;<br>//obtain a sequence of points of contour, pointed by the variable 'contour'<br>contours = contours->h_next;<br>}<br>cout << "contours end = " << endl << " " << contours << endl << endl;<br>return 0;<br>}<br><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style:
 normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;">when i convert to lisp(below ...i didnt add while loop because h-next is null),  i use nested  with-foreign-slots to access the h-next member for debugging. it is  a null pointer where in the c code above the h_next member is full of data...the function does work though....it works as good as it does in c<br><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier
 New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;">(let* ((img (load-image "/home/w/quicklisp/dists/quicklisp/software/cl-opencv-master/images/FindingContours.png" 1))<br>       (img-size (get-size img))             <br>       (img-grayscale (create-image img-size +ipl-depth-8u+ 1))<br>       (storage (create-mem-storage 0))<br>       ( contours (create-seq +seq-eltype-point+ (cffi:foreign-type-size '(:struct cv-seq)) <br>                 (cffi:foreign-type-size '(:struct cv-point))
 storage)))<br>      (find-contours img-grayscale  storage contours <br>             (cffi:foreign-type-size '(:struct cv-contour)) +retr-list+ <br>             +chain-approx-simple+ (make-cv-point :x 0 :y 0))<br>     <br>      (cffi:with-foreign-slots ((h-next) <br>                  contours   (:struct cv-seq))<br>    <br>    (cffi:with-foreign-slots ((h-next) <br>                  h-next (:struct cv-seq))<br>     <br>            h-next)<br>    <br>   
       ))<br><br><br>just outputs a null-pointer>> #.(SB-SYS:INT-SAP #X00000000)<br><br>any help on this would be appreciated?<br><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: Courier New,courier,monaco,monospace,sans-serif; background-color: transparent; font-style: normal;"><br></div></div></body></html>