tof 相机的数据读取,depth data和amplitude data以及3D数据[通俗易懂]

tof 相机的数据读取,depth data和amplitude data以及3D数据[通俗易懂]1.开发前提如果相机带有SDK也就是开发需要的工具以及包,就要用相机带的开发包,里面包含了相应的读取文件的函数,以及设置的相机的相关函数。本文使用的是TTF相机,C++头文件代码如下:#include"../../include/TTF_API.h"#include<unistd.h>usingnamespacestd;usingnamespaceV…

大家好,又见面了,我是你们的朋友全栈君。

1.开发前提

如果相机带有SDK 也就是开发需要的工具以及包,就要用相机带的开发包,里面包含了相应的读取文件的函数,以及设置的相机的相关函数。

本文使用的是TTF相机,C++头文件代码如下:

#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++代码如下:

#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.主函数的实现:

主函数未使用线程,只是比较简单的数据的读取 代码如下,

#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数据的显示。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/141345.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • VS2008 安装失败(“Web 创作组件”无法)

    VS2008 安装失败(“Web 创作组件”无法)今天安装VS2008时出现了问题,怎么都无法安装成功。于是在网上找答案,还真给找到了。贴出来大家学习一下。VisualStudio2008中文正式版可以从微软网站下载试用了,因为之前用英文版感觉比2005快一些,虽然.NETFramework3.5有点庞大,但还是可以选择开发2.0的项目,因此打算立马安装。试用期为三个月,足够长了,因此安装TeamSystem版本,体验

    2022年9月6日
    2
  • vue 富文本编辑框_基于vue的富文本编辑器

    vue 富文本编辑框_基于vue的富文本编辑器1、下载插件npmiwangeditor–save插件官网地址:https://www.wangeditor.com/2、封装富文本组件<templatelang=”html”><divclass=”editor”><!–<divref=”toolbar”class=”toolbar”></div>–><divref=”editor”class=”text”></div

    2022年10月9日
    0
  • Python-random函数用法

    Python-random函数用法Python标准库中的random函数,可以生成随机浮点数、整数、字符串,甚至帮助你随机选择列表序列中的一个元素,打乱一组数据等。random中的一些重要函数的用法:random.random()random.random()函数是这个模块中最常用的方法了,它会生成一个随机的浮点数,范围是在0.0~1.0之间。importrandomprint(random.random())&…

    2022年5月2日
    52
  • js获取request中的值_set协议工作原理

    js获取request中的值_set协议工作原理设置http请求头HttpURLConnection.setRequestProperty(Stringkey,Stringvalue); 这个我居然都忘记了,哎~真是岁数大了,心好累。。。 例如:下面就是一个完整的原始网络请求方式HttpURLConnectionconn=null;try{…

    2022年9月11日
    0
  • three.js创建简单的3D机房(1) 创建机柜模型-2

    three.js创建简单的3D机房(1) 创建机柜模型-2/****创建机柜门接上一篇*/letrearGeometryDoor=newTHREE.BoxGeometry(basicParameters.thickness,this.cabinetObj.h,this.cabinetObj.w+basicParameters.thickness*2);letmaterialsbgDoor=[];for(leti=0;i<rearGeometryDoor.faces.length/2;i+=1)

    2022年10月25日
    0
  • ETH硬分叉降低了显卡矿机的挖矿收益吗?

    ETH硬分叉降低了显卡矿机的挖矿收益吗?“北京时间2019年3月1日凌晨3:52分,ETH完成了君士坦丁堡硬分叉升级。这场从2018年8月份就开始计划的硬分叉,几经波折,但最终是平稳顺利的。虽然对比其他主流币种轰轰烈烈的硬分叉,ETH这次硬分叉显得过于平淡,但还是有很多矿工朋友想知道它是否降低了ETH的挖矿收益,未来挖矿收益如何变化,显卡矿机未来的出路在哪里?”笔者根据最近一年的ETH挖矿难度、挖矿收益、币价等变化情况,做了一些…

    2022年6月9日
    44

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号