How would I go about wrapping an opencv macro with cffi/lisp?

328 views Asked by At

I'm used to wrapping functions but I'm trying to wrap the function cvStartWriteSeq and it appears to use a macro - CV_WRITE_SEQ_ELEM - to write elements to a opencv sequence...

here is the code isaw where I discovered that:

CvSeqWriter writer;
cvStartWriteSeq( CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage, &writer );
for( i = 0; i < 100; i++ )
{
CvPoint pt; pt.x = rand()%320; pt.y = rand()%240;
CV_WRITE_SEQ_ELEM( pt, writer );
}
CvSeq* seq = cvEndWriteSeq( &writer );

I'm familiar with using defcfun to wrap functions but in the /modules/core/include/opencv2/core/types_c.h I saw the macro and I was curious as how I would accomplish the task. here is the macro definition...

#define CV_WRITE_SEQ_ELEM( elem, writer )             \
{                                                     \
     assert( (writer).seq->elem_size == sizeof(elem)); \
     if( (writer).ptr >= (writer).block_max )          \
     {                                                 \
         cvCreateSeqBlock( &writer);                   \
     }                                                 \
     assert( (writer).ptr <= (writer).block_max - sizeof(elem));\
     memcpy((writer).ptr, &(elem), sizeof(elem));      \
     (writer).ptr += sizeof(elem);                     \
}

any guidance on how I would do this would speed up the process of getting a complete Lisp opencv wrapper and be greatly appreciated =)

1

There are 1 answers

0
Stelian Ionescu On