是否可以使用 pybind 将缓冲区发送到 python 函数?

问题描述 投票:0回答:0

我已经能够将向量、整数、浮点数等发送到 python 函数,但现在我想发送一个缓冲区。我希望 python 函数在对其进行一些处理后返回数据。我知道我在处理后遗漏了一些步骤,但现在我只想发送一个缓冲区而不是一个向量。我无法在网上找到任何示例,但是这个 documentation.

这是我在 C++ 中的模板化函数:

template <typename TYPE>
TYPE callPythonMethodPtrParam(std::string const&methodName, TYPE* data)
{
    py::object obj = mModule();
    py::object method = obj.attr(methodName.c_str());
    py::object result = method(data);
    TYPE returnValue{result.cast<TYPE>()};
    return returnValue;
};

这是我的 python 函数:

def process(self, inputArray):
    # do processing
    return inputArray
python c++ ctypes pybind11
© www.soinside.com 2019 - 2024. All rights reserved.