歡迎訪問我的個(gè)人博客: zengzeyu.com
前言
在進(jìn)行網(wǎng)絡(luò)訓(xùn)練過程中,在生成訓(xùn)練數(shù)據(jù)時(shí),一般會(huì)使用比較底層的傳感器來生成數(shù)據(jù),如攝像頭或雷達(dá),所以大部分使用C++進(jìn)行開發(fā)。為了將數(shù)據(jù)轉(zhuǎn)為Numpy Array格式供Python調(diào)用,cnpy庫就是供C++生成這種格式數(shù)據(jù)的開源庫,由國外一名小哥開發(fā)。
cnpy地址:https://github.com/rogersce/cnpy
官方例子:https://github.com/rogersce/cnpy/blob/master/example1.cpp
應(yīng)用方法
cnpy有兩種應(yīng)用方法:
- 官網(wǎng)方法:將cnpy庫加入到ubuntu系統(tǒng)環(huán)境中,當(dāng)做系統(tǒng)庫進(jìn)行調(diào)用,類似于安裝好的OpenCV庫;
- ROS package 方法:將cnpy庫包含到ROS工作空間下,當(dāng)做獨(dú)立的package供調(diào)用。
方法1:
按照官網(wǎng)安裝教程安裝即可:
Installation:
Default installation directory is /usr/local. To specify a different directory, add -DCMAKE_INSTALL_PREFIX=/path/to/install/dir to the cmake invocation in step 4.
1. get [cmake](https://github.com/rogersce/cnpy/blob/master/www.cmake.org)
2. create a build directory, say $HOME/build
3. cd $HOME/build
4. cmake /path/to/cnpy
5. make
6. make install
Using:
To use, #include"cnpy.h" in your source code. Compile the source code mycode.cpp as
g++ -o mycode mycode.cpp -L/path/to/install/dir -lcnpy -lz --std=c++11
方法2:
- 將下載好的
cnpy文件夾放到與調(diào)用cnpy庫的 package A 同級目錄下,并將以下內(nèi)容添加到A的package.xml中:
<build_depend>cnpy</build_depend>
<run_depend>cnpy</run_depend>
- 然后以下內(nèi)容添加到 A 的
Cmakelist.txt中:
find_package(
cnpy )
catkin_package(
CATKIN_DEPENDS cnpy )
- 在 A 中調(diào)用的
xx.h中按照路徑包含即可:
#include "../../../cnpy/include/cnpy/cnpy.h"
此方法也適用于任何其他想要調(diào)用的package,按照上書步驟操作即可。
以上。