Code: Select all
CvSeq* contours; //hold the pointer to a contour in the memory block
// adds data to CvSeq* contours with &contours call
cvFindContours(imgGrayScale, storage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
// This is how its supposed to work ....no matter how many times you dereference contours to get the h_next struct member
// the value of contours->h_next is always the same
cout << "c1 = " << endl << " " << contours->h_next << endl << endl; //output same as next line - see output below
cout << "c2 = " << endl << " " << contours->h_next << endl << endl; //output same as above line see output below
// If you assign contours->h_next to a new variable "c"
CvSeq* c = contours->h_next;
// then cout contours->h_next the output of the below 2 cout's is still the same as the output of the above 2 - see output below
cout << "c3 = " << endl << " " << contours->h_next << endl << endl;
cout << "c4 = " << endl << " " << contours->h_next << endl << endl;
// but if you assign contours->h_next back to contours the output of the next 2 couts is different than above 4
// see output below
contours = contours->h_next;
cout << "c5 = " << endl << " " << contours->h_next << endl << endl;
cout << "c6 = " << endl << " " << contours->h_next << endl << endl;
Code: Select all
c1 =
0x182f730
c2 =
0x182f730
c3 =
0x182f730
c4 =
0x182f730
c5 =
0x182f560
c6 =
0x182f560
The struct CvSeq is defined as this
Code: Select all
#define CV_TREE_NODE_FIELDS(node_type) \
int flags; /* Miscellaneous flags. */ \
int header_size; /* Size of sequence header. */ \
struct node_type* h_prev; /* Previous sequence. */ \
struct node_type* h_next; /* Next sequence. */ \
struct node_type* v_prev; /* 2nd previous sequence. */ \
struct node_type* v_next /* 2nd next sequence. */
/*
Read/Write sequence.
Elements can be dynamically inserted to or deleted from the sequence.
*/
#define CV_SEQUENCE_FIELDS() \
CV_TREE_NODE_FIELDS(CvSeq); \
int total; /* Total number of elements. */ \
int elem_size; /* Size of sequence element in bytes. */ \
schar* block_max; /* Maximal bound of the last block. */ \
schar* ptr; /* Current write pointer. */ \
int delta_elems; /* Grow seq this many at a time. */ \
CvMemStorage* storage; /* Where the seq is stored. */ \
CvSeqBlock* free_blocks; /* Free blocks list. */ \
CvSeqBlock* first; /* Pointer to the first sequence block. */
typedef struct CvSeq
{
CV_SEQUENCE_FIELDS()
}
CvSeq;
Code: Select all
(cffi:defcstruct cv-seq
(flags :int)
(header-size :int)
(h-prev :pointer)
(h-next :pointer)
(v-prev :pointer)
(v-next :pointer)
(total :int)
(elem-size :int)
(block-max :pointer)
(ptr :pointer)
(delta-elems :int)
(storage :pointer)
(free-blocks :pointer)
(first :pointer))
with the below code my output is the same for both princ...not newline of course =)
Code: Select all
(with-foreign-object (contours '(:pointer (:struct cv-seq)))
(find-contours img-grayscale storage contours
(size-of cv-contour) +retr-list+
+chain-approx-simple+ (point 0 0))
(with-foreign-slots ((h-next) contours (:struct cv-seq))
(setf contours h-next)
(princ contours)
(princ #\newline)
(setf contours h-next)
(princ contours)))
Cheers!