网上的simpleviewer可参考

本文介绍了网上可以找到的C++ SimpleViewer参考资料,特别提到了一篇来自2012年的博客文章,该文章的主要优点是对代码有注释,而Orbbec提供的版本则缺少注释。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网上的simpleviewer可参考

c++

********************************************

[源文章(https://www.cnblogs.com/yemeishu/archive/2012/12/25/2832024.html)
主要的有点是有注释,orbbec给的没有注释

#include "stdafx.h"
#include <iostream>
#include <OpenNI.h>
#include "Viewer.h"
 
int main(int argc, char** argv)
{
    openni::Status rc = openni::STATUS_OK;
 
    openni::Device device;
    openni::VideoStream depth, color;
    const char* deviceURI = openni::ANY_DEVICE;
 
    // 1. 初始化OpenNI.
    rc = openni::OpenNI::initialize();
 
 
    // 2. 打开Kinect设备,这里deviceURI设置为openni::ANY_DEVICE
    /*
    * (1) 如果有多个装置,xiangyao指定要用哪个装置的话,需要先通过
    * static void openni::OpenNI::enumerateDevices(Array<DeviceInfo>* deviceInfoList) 
    * 这个函数获取可使用的装置列表,在通过指定的URI的方式,来指定要开启的装置;
    * (2) 如果没有要特别指定的话或者只有一个装置的话,则是用openni::ANY_DEVICE作为URI,让系统
    * 决定要使用的装置.
    */
    rc = device.open(deviceURI);
     
    // 3. openni::SENSOR_DEPTH表示创建深度数据流;
    /************************************************************************/
    /* 这里的create()函数的第二个参数是一个枚举类型enum openni::SensorType,主要有
     * 三个Enumerator:SENSOR_IR, SENSOR_COLOR和SENSOR_DEPTH.通过字面也知道他们是
     * 分别要获取哪个类型的数据流信息。
    */
    /************************************************************************/
    rc = depth.create(device, openni::SENSOR_DEPTH);
    if (rc == openni::STATUS_OK)
    {
        // 4. 透过start和stop函数来控制数据流的读取。
        rc = depth.start();
        if (rc != openni::STATUS_OK)
        {
            printf("SimpleViewer: Couldn't start depth stream:\n%s\n", openni::OpenNI::getExtendedError());
            depth.destroy();
        }
    }
    else
    {
        printf("SimpleViewer: Couldn't find depth stream:\n%s\n", openni::OpenNI::getExtendedError());
    }
    // 同样的利用openni::SENSOR_COLOR读取颜色图像数据流。
    rc = color.create(device, openni::SENSOR_COLOR);
    if (rc == openni::STATUS_OK)
    {
        rc = color.start();
        if (rc != openni::STATUS_OK)
        {
            printf("SimpleViewer: Couldn't start color stream:\n%s\n", openni::OpenNI::getExtendedError());
            color.destroy();
        }
    }
    else
    {
        printf("SimpleViewer: Couldn't find color stream:\n%s\n", openni::OpenNI::getExtendedError());
    }
 
    if (!depth.isValid() || !color.isValid())
    {
        printf("SimpleViewer: No valid streams. Exiting\n");
        openni::OpenNI::shutdown();
        return 2;
    }
 
    // 5. 根据获取到的深度数据流和彩色图像数据流,创建SampleViewer对象,显示深度图像。
    SampleViewer sampleViewer("Simple Viewer", device, depth, color);
 
    rc = sampleViewer.init(argc, argv);
    if (rc != openni::STATUS_OK)
    {
        openni::OpenNI::shutdown();
        return 3;
    }
    sampleViewer.run();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值