使用 Swig 将使用 OpenCV 的 C 函数绑定到 python
我每天使用 OpenCV 及其 Python 包装器来生成计算机视觉算法。
对于几个复杂的函数,我们需要保留 C 版本,这样可以缩短计算时间并更容易重用。
通过这种方式,我想绑定使用opencv结构(如iplimage)的C函数以在Python中使用它们。你能给我一些建议吗?我 实际上不知道从哪里开始。
这是我的结构,其中包含 ipimages。
typedef struct{
int nbBlobs;
IplImage *labels;
IplImage *contours;
}ccl_conf_t;
这是我的函数的原型:
int ccl_init(ccl_conf_t *conf, IplImage *frame);
void ccl_unInit(ccl_conf_t *conf);
int ccl_label(ccl_conf_t *conf, IplImage *frame, int option);
如果您能给我任何提示,我将不胜感激!
I use OpenCV and its Python wrappers on a daily basis to produce computer vision algorithms.
For several complex functions, we need to keep the C version which allows lower computation time and easier reuse.
In this way, I would like to bind C functions that use opencv structures like iplimage to use them in Python. Could you give me some tips on it? I
don't really know where to start actually.
Here is my structure which contains iplimages.
typedef struct{
int nbBlobs;
IplImage *labels;
IplImage *contours;
}ccl_conf_t;
And here are the propotypes of my function:
int ccl_init(ccl_conf_t *conf, IplImage *frame);
void ccl_unInit(ccl_conf_t *conf);
int ccl_label(ccl_conf_t *conf, IplImage *frame, int option);
I would be grateful for any hint you could give me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用 C 语言制作 Python 可加载模块非常容易。从这里开始: http://docs.python.org/c-api/
很容易从 Python 源代码本身中获取一个小示例,扩展到您自己的使用。查看 Python 源代码的“模块”目录。
Making a Python loadable module in C is quite easy. Start here: http://docs.python.org/c-api/
It's easy to take a small example from the Python source itself, extend to your own use. Look in the 'Modules' dir of the Python source.