简体   繁体   English

Boost.Python:独立python脚本无法使用转换器

[英]Boost.Python: Converters unavailable from standalone python script

The title may not be as explicit as I wish it would be but here is what I am trying to achieve: 标题可能不像我希望的那样明确,但这是我想要实现的目标:

Using Boost.Python, I expose a set of class/functions to Python in the typical BOOST_PYTHON_MODULE(MyPythonModule) macro from C++ that produces MyPythonModule.pyd after compilation. 使用Boost.Python,我在C ++中典型的BOOST_PYTHON_MODULE(MyPythonModule)宏中向Python公开了一组类/函数,该宏在编译后生成MyPythonModule.pyd I can now invoke a python script from C++ and play around with MyPythonModule without any issue (eg. create objects, call methods and use my registered converters ). 现在,我可以从C ++调用python脚本并使用MyPythonModule而不会出现任何问题(例如,创建对象,调用方法和使用我注册的转换器 )。 FYI: the converter I'm refering to is a numpy.ndarray to cv::Mat converter. 仅供参考:我指的转换器是numpy.ndarray到cv :: Mat转换器。

This works fine, but when I try to write a standalone Python script that uses MyPythonModule , my converters are not available. 这可以正常工作,但是当我尝试编写使用MyPythonModule的独立Python脚本时,我的转换器不可用。 I tried to expose the C++ method that performs the converter registration to Python without any luck. 我试图向C公开执行转换器注册的C ++方法,但没有任何运气。

If my explanation isn't clear enough, don't hesitate to ask questions in the comments. 如果我的解释不够清楚,请随时在评论中提问。

Thanks a lot for your help / suggestions. 非常感谢您的帮助/建议。

I found the problem... The prototype of my C++ function was taking cv::Mat& as argument and the converter was registered for cv::Mat without reference. 我发现了问题...我的C ++函数的原型以cv::Mat&作为参数,并且该转换器已为cv::Mat注册而没有引用。

That was silly. 那真是愚蠢。

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

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