tof 相机的数据读取,depth data和amplitude data以及3D数据
2018-10-19 13:52
771 查看
1.开发前提
如果相机带有SDK 也就是开发需要的工具以及包,就要用相机带的开发包,里面包含了相应的读取文件的函数,以及设置的相机的相关函数。
本文使用的是TTF相机,C++头文件代码如下:
[code]#include "../../include/TTF_API.h" #include <unistd.h> using namespace std; using namespace Voxel; class Depth_Camera { public: Depth_Camera(); ~Depth_Camera(); TTF_API::_ttfDeviceInfo m_pDevInfo[MAX_DEVICE]; DepthFrame *m_pDepthFrame; XYZIPointCloudFrame *m_pPCLFrame; int ReadDepthFrame(const DepthFrame* pDepthFrame); int ReadPointCloudFrame(const XYZIPointCloudFrame* pXYZIPointCloudFrame); bool System_init(); int Buffer_init(); void Data_Depth(); void Data_PCL(); void Device_Close(); void Device_Stop(); };
其中TTF::相关函数是相机自带的接口。
2.读取数据:
函数的实现部分,c++代码如下:
[code]#include "Depth_Camera.h" Depth_Camera::Depth_Camera() { } Depth_Camera::~Depth_Camera() { } //读取相关内容 int Depth_Camera::ReadDepthFrame(const DepthFrame* pDepthFrame) { const DepthFrame *d = pDepthFrame; const float* data; data = d->depth.data(); cout<< "depth:"<< d->id << "@" << d->timestamp << " data:" << data[320*120+160] << endl; return TTF_API::ERROR_NO; } int Depth_Camera::ReadPointCloudFrame(const XYZIPointCloudFrame* pXYZIPointCloudFrame) { const XYZIPointCloudFrame *d = pXYZIPointCloudFrame; cout<< "pcl:" << d->id << "@" << d->timestamp << " data:" << d->points[320*120+160].z << endl; return TTF_API::ERROR_NO; } //函数初始化 bool Depth_Camera::System_init() { int nDevCount;//device count int nDevOpened; TTF_API::ttfGetDeviceList(m_pDevInfo, nDevCount); if (nDevCount < 1) { std::cerr << "No Camera Found!, Please connection check and restart." "Connection Error" << std::endl; } else { nDevOpened = TTF_API::ttfDeviceOpen(m_pDevInfo[0].hnd); if (nDevOpened > 0) { //Callback Register //回调函数, TTF_API::ttfRegister_Callback_DepthFrame(std::bind(&Depth_Camera::ReadDepthFrame, this, std::placeholders::_1)); TTF_API::ttfRegister_Callback_PointCloudFrame(std::bind(&Depth_Camera::ReadPointCloudFrame, this, std::placeholders::_1)); std::cout << "Camera[VID:" << m_pDevInfo[0].nVendorId << ", PID:" << m_pDevInfo[0].nProductId << ", SerialNum:" << m_pDevInfo[0].szSerialNum << "] Open Success" << endl; } else { return TTF_API::ERROR_OPEN; } Buffer_init(); } Data_Depth();//start Depth //imshow("Binary", pDepthFrame); return TTF_API::ERROR_NO; } int Depth_Camera::Buffer_init() { m_pDepthFrame = (DepthFrame*)malloc(sizeof(DepthFrame));; m_pPCLFrame = (XYZIPointCloudFrame*)malloc(sizeof(XYZIPointCloudFrame)); if(m_pDepthFrame == NULL || m_pPCLFrame == NULL) { cout << "Failed to create nescecary buffers to display the image" << endl; return TTF_API::ERROR_FAIL; } else return TTF_API::ERROR_NO; } void Depth_Camera::Data_Depth() { TTF_API::ttfClearCallback(m_pDevInfo[0].hnd, TTF_API::FrameType::FRAME_XYZI_POINT_CLOUD_FRAME); TTF_API::ttfDeviceStart(m_pDevInfo[0].hnd, TTF_API::FrameType::FRAME_DEPTH_FRAME); } void Depth_Camera::Data_PCL() { TTF_API::ttfClearCallback(m_pDevInfo[0].hnd, TTF_API::FrameType::FRAME_DEPTH_FRAME); TTF_API::ttfDeviceStart(m_pDevInfo[0].hnd, TTF_API::FrameType::FRAME_XYZI_POINT_CLOUD_FRAME); } void Depth_Camera::Device_Close() { TTF_API::ttfDeviceStop(m_pDevInfo[0].hnd); TTF_API::ttfDeviceClose(m_pDevInfo[0].hnd); } void Depth_Camera::Device_Stop() { TTF_API::ttfDeviceStop(m_pDevInfo[0].hnd); }
3.主函数的实现:
主函数未使用线程,只是比较简单的数据的读取 代码如下,
[code]#include "Depth_Camera.h" int main() { Depth_Camera *depth_camera = new Depth_Camera; int nRet; nRet = depth_camera->System_init(); if(nRet < 1) { cout << "init Error :" << nRet << endl; exit(0); } char getkey; while(1) { getkey = getchar(); //Reading end Process if(getkey == 'q') { depth_camera->Device_Close(); break; } else if(getkey == '2')//Depth { depth_camera->Data_Depth(); } else if(getkey == '3')//PCL { depth_camera->Data_PCL(); } else if(getkey == 's') { depth_camera->Device_Stop(); } } if(depth_camera != NULL) { delete depth_camera; depth_camera = NULL; } return 0; }
4.今天只写数据的简单读取,下次完成深度数据以及3D数据的显示。
阅读更多相关文章推荐
- JavaPoi技术二-------导出数据到Excel以及从excel中读取数据
- geotrellis使用(二)geotrellis-chatta-demo以及geotrellis框架数据读取方式初探
- 从数据库sqlite3读取数据以及等等操作~~~~~应有尽有
- react native AsyncStorage 使用实例 异步存储数据以及读取
- PHP 数据库mysql链接,以及读取数据内容方式详解
- npoi的下拉框操纵 以及数据读取 以及下拉框字符超过255的解决方法 不需要高版本excel
- WP7的XML操作详解:读取,过滤以及数据绑定
- R语言学习第五天----数据读取以及数据保存
- 提取TOF相机点云数据griddate mesh 画图
- 关于利用opendatasource 读取excel文件中的数据问题以及更新数据库中对应数据的问题
- java中读取文件以及向文件中追加数据的总结
- Spark将数据写入Hbase以及从Hbase读取数据
- 查看ros中laser和camera读取的数据以及该数据的含义
- TWaver 3D 编辑器的使用(一)----设计3D场景以及数据绑定
- python数据分析第一步:读取以及查看数据
- 用python读取以及存储数据数据
- 读取数据库的数据并整合成3D饼图在jsp中显示详解
- 网页读取数据,以及输入输出流的代码收集
- MySQL中游标使用以及读取文本数据
- BioUsb-线程中读取数据至缓冲以及将缓冲数据保存在m_ObArray中