保存数据(矩阵或ndarray),然后将其加载到C++ (作为OpenCV垫子)
我已经在numpy中创建了一些我想在单独的C ++程序中使用的数据。因此,我需要使用Python保存数据,然后将其加载到C ++中。这样做的最好方法是什么?
我的numpy ndarray是浮动32,形状[10000 x 18 x 5]。例如,我可以保存它,例如使用
numpy.save(filename, data)
C ++中加载此类数据的简便方法吗?目标结构可以是eigen :: matrix
。
I've created some data in numpy that I would like to use in a separate C++ program. Therefore I need to save the data using python and later load it in C++. What is the best way of doing this?
My numpy ndarray is float 32 and of shape [10000 x 18 x 5]. I can save it for example using
numpy.save(filename, data)
Is there an easy way to load such data in C++? Target structure could be an Eigen::Matrix
for example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
搜索几个小时后,我找到了我一年过去了的示例文件。
警告:
,将numpy数组写入ASCII文件,并用标头指定nrows,ncols,ncols:
示例输出data-file.txt,看起来像这样(第一行是header指定NROWS和NCOLS):
CPP):CPP ):CPP):CPP):CPP函数将ASCII文件中的矩阵读取到OPENCV矩阵:
在CPP程序中使用上述函数的驱动程序代码:
完整性,一些代码使用C ++保存数据:
未来工作:未来的工作:
After searching for hours I found my year-old example files.
Caveat:
Write numpy array to ascii file with header specifying nrows, ncols:
Example output data-file.txt looks like this (first row is header specifying nrows and ncols):
Cpp function to read matrix from ascii file into OpenCV matrix:
Driver code to use above mentioned function in cpp program:
For completeness, some code to save the data using C++:
Future work: