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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Ubuntu安装python3和pip3

    Ubuntu安装python3和pip31、下载安装包:Python官网下载选择对应的版本下载.tgz文件。2、解压文件,进入文件夹。在终端运行:./configure编译:make测试:maketest安装:sudomakeinstall如果安装出现:make:***[install]Error1不用管。运行:python3.7.33.7.3是我安装的版本,将版本号换成自己的,能进入python环境就说明安装成功了。3、设置为默认的版本python指向python3.7.3。删除原有的链接:sudorm/u

    2022年6月23日
    33
  • 5G科普——5G切片[通俗易懂]

    5G科普——5G切片[通俗易懂]切的是什么?先了解为什么会提出网络切片这一概念。5G服务是多样化的,包括车联网、大规模的互联网、工业自动化、远程医疗、VR/AR等这些服务对我们的要求是不一样的,有的低延时、高可靠;有的高清、高速率;有的大连接、低移动性;因此5G网络要满足差异化的业务,需要能够像搭积木一样灵活部署,方便新业务的上线下线,于是网络切片这一概念应运而生。3GPP定义:网络切片是提供特定网络能力和网络特性的逻辑网…

    2022年10月2日
    2
  • Springboot引入本地jar包,并通过maven把项目成功打包成jar包部署[通俗易懂]

    Springboot引入本地jar包,并通过maven把项目成功打包成jar包部署[通俗易懂]引入钉钉的sdk打包到线上,各种报错:ClassNofFoundException…第一步:将jar包放到resource的lib文件夹下:第二部:在pom文件中引入:第三部:继续修改pom文件的打包插件配置:<includeSystemScope>true</includeSystemScope>打包时候IDEA还是会报警告,不用管它;…

    2022年6月29日
    23
  • 理解51单片机最小系统的工作原理「建议收藏」

    理解51单片机最小系统的工作原理「建议收藏」51单片机最小应用系统概述要想使用单片机,第一个要搭建的电路就是单片机的最小系统,有了这个最小系统单片机就可以去正常的工作,即使没有其他的外围电路(显示器啥的),也可以对单片机进行程序的编写,程序也可以在单片机里面正常的运行。其包括MCS-51系列芯片一块,(51初步认识)电源电路,时钟电路,复位电路。51单片机最小系统原理图1.电源电路任何的电子设备都需要给其供应相对应的工作电源才可以正常工作,此芯片可用+5V的直流电源供电电源电路2.时钟电路单片机的芯片是数字电路芯片,数字芯片要想正常

    2022年6月23日
    34
  • 对贝叶斯理解以及解释贝叶斯函数「建议收藏」

    对贝叶斯理解以及解释贝叶斯函数「建议收藏」贝叶斯

    2022年5月7日
    69
  • jQuery遮罩层登录对话框

    用户登录是许多网站必备的功能。有一种方式就是不管在网站的哪个页面,点击登录按钮就会弹出一个遮罩层,显示用户登录的对话框。这用方式比较灵活方便。而现在扫描二维码登录的方式也是很常见,例如QQ、微信、百度

    2021年12月28日
    37

发表回复

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

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