我已经用SWIG成功包装了我的C++代码,并且可以很好地加载到Python中。我正在使用Olena library for image processing。
但是,我不知道如何调用需要指向图像指针的函数!
例如,我侵 eclipse 图像的函数原型(prototype)如下:
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);
}
你怎么看待这件事?