C++键入dtype(如何从numpy数组初始化cv ::垫子)
pybind11在 numpy.h
中具有以下方法:
/// Return dtype associated with a C++ type.
template <typename T>
static dtype of() {
return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::dtype();
}
如何获得逆?来自类型 dtype
的变量的C ++类型?
编辑
我最初的问题是我想将OpenCV图像从Python带到C ++,如所述>请注意,此答案中完成的演员始终为 unsigned char*
:
cv::Mat img2(rows, cols, type, (unsigned char*)img.data());
我想做的是使用 .dtype()
获取“ Python type “然后做正确的演员。
因此,我的功能签名将 py ::数组
作为参数。
int cpp_callback1(py::array& img)
{
//stuff
cv::Mat img2(rows, cols, type, (unsigned char*)img.data());
^^^ Somehow I want this to be variable
//more stuff
}
也许我可以从我的 dtype
获得 type_id
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cv :: mat
具有接受数据指针的void*
。因此,您无需将
dtype
转换为C ++类型。您可以简单地使用:
cv::Mat
has a constructor that accepts avoid*
for the data pointer.Therefore you don't need to convert the
dtype
into a C++ type.You can simply use: