繁体   English   中英

通过引用从Python调用C ++函数

[英]Call C++ function from Python by reference

我用SWIG成功地包装了我的C ++代码,它可以很好地加载到Python中。 我正在使用Olena库进行图像处理

但是,我不知道如何调用需要指向图像的指针的函数!

例如,我的侵蚀图像的功能原型如下:

mln::image2d<mln::value::int_u8> imErossion(
    const mln::image2d<mln::value::int_u8> *img, int size, int nbh
);

在Python中运行我的代码的结果:

    from swilena import *
    from algol import *

    image = image2d_int_u8
    ima = image.load("micro24_20060309_grad_mod.pgm")

    eroded_ima = imErossion(ima,1,8) 
    >>>> Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: in method 'imErossion', argument 1 of type 
       'mln::image2d<mln::value::int_u8 > const *'

我一直在网上寻找尝试自己解决这个问题,但它变得比我预期的更难。

我不确定如何从Python传递指针 - 相当于这个C ++代码:

eroded_ima = imErossion(&ima,1,8)

我和我在大学的教授一起检查过,我们决定最好实现一个函数,当这个函数被加载并声明为全局时,它会返回指向图像的指针:

mln::image2d<mln::value::int_u8> working_img;

mln::image2d<mln::value::int_u8> *imLoad(const std::string path){
    mln::io::pgm::load(working_img, path);
    return &working_img;
}

void imSave(const std::string path){

    mln::io::pgm::save(working_img, path);

}

你怎么看待这件事?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM