2

我习惯于包装函数,但我试图包装函数 cvStartWriteSeq 并且它似乎使用宏 - CV_WRITE_SEQ_ELEM - 将元素写入opencv序列......

这是我发现的代码isaw:

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 );

我熟悉使用 defcfun 来包装函数,但是在 /modules/core/include/opencv2/core/types_c.h 中我看到了宏,我很好奇我将如何完成任务。这是宏定义...

#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);                     \
}

任何关于我如何做到这一点的指导都将加快获得完整 Lisp opencv 包装器的过程,非常感谢 =)

4

1 回答 1

2

CFFI 有一个我专门为这种情况编写的 ASDF 扩展:包装 C 宏。示例: https ://github.com/sionescu/iolib/blob/ee8d3e538b6a4f0433b6e53e2d0bd767ba879149/iolib.syscalls.asd https://github.com/sionescu/iolib/blob/ee8d3e538b6a4f0433b6e53e2d0bd767ba879149/syscalls/ffi

于 2013-10-05T21:40:34.993 回答