ni-hello

Overview

This example shows how to connect to camera and get device info.

Expect Output

Name:TS800
Uri:USB#VID_2DF2&PID_0213&REV_0007&BUS_02&ADR_10
USB Product ID:531
USB Vendor ID:11762
Vendor:LIPS

Tutorial

  • Import openni header

#include <openni2/OpenNI.h>
  • Initialize SDK

if (openni::OpenNI::initialize() != openni::STATUS_OK)
{
    printf("Initialize Failed:%s\n", openni::OpenNI::getExtendedError());
    return -1;
}
  • Scan connected devices

openni::Array<openni::DeviceInfo> deviceList;
openni::OpenNI::enumerateDevices(&deviceList);
  • Connect to camera and get camera device info

Or you can use open(openni::ANY_DEVICE) to connect to the first found device.

for (int i = 0; i < deviceList.getSize(); i++)
{
    openni::DeviceInfo info = deviceList[i];
    printf("Name:%s\n", info.getName());
    printf("Uri:%s\n", info.getUri());
    printf("USB Product ID:%s\n", info.getUsbProductId());
    printf("USB Vendor ID:%s\n", info.getUsbVendorId());
    printf("Vendor:%s\n", info.getVendor());
}

openni::Device device;
if (device.open(deviceList[0].getUri()) != openni::STATUS_OK)
{
    printf("Cannot open device: %s\n", openni::OpenNI::getExtendedError());
    return -1;
}
  • Close camera and deconstruct OpenNI SDK

device.close();
openni::OpenNI::shutdown();

Full code

ni-hello.cpp

Last updated