orbbec viewer
TRANSCRIPT
Orbbec Viewer 手册
1. 概述
Orbbec Viewer是基于Orbbec OpenNI2 SDK开发的工具,帮助开发者快速使用Orbbec的3D传感器产品。
Orbbec OpenNI2 扩展 API 是基于OpenNI2 实现了 Orbbec 3D传感器产品的特性功能,包括读取序列号、获取设备类型、相机参数、控制等功能。
本文档对这些功能进行了描述并演示了基本使用的过程。
2. 范围
支持设备:Orbbec 3D 传感器,包括 Astra,Astra Pro, Astra Mini等。
扩展API支持平台:Windows x86/x64,Ubuntu 16.04 及以上 x86/x64/ARM/ARM64,Android 4.4+
Orbbec Viewer演示平台:Windows x86/x64
3. 介绍
Orbbec OpenNI2 扩展 API 支持Windows x86/x64, Linux x86/x64/ARM/ARM64 和Android。 在使用扩展API之前,先要初始化Orbbec OpenNI2并成功打开设备。Orbbec Viewer(Windows版本)中演示了所有扩展API的使用。
本工具基于OpenCV来使用UVC模式的彩色相机。
4. 获取序列号
5. 获取设备类型
char serNumber[12];
int dataSize = sizeof(serNumber);
memset(serNumber, 0, dataSize);
g_Device.getProperty(openni::OBEXTENSION_ID_SERIALNUMBER, (uint8_t
*)&serNumber, &dataSize);
1
2
3
4
char devType[32];
int dataSize = sizeof(devType);
memset(devType, 0, dataSize);
g_Device.getProperty(openni::OBEXTENSION_ID_DEVICETYPE, (uint8_t *)&devType,
&dataSize);
1
2
3
4
6. 获取相机参数
7. 获取红外增益值
8. 设置红外增益值
typedef struct OBCameraParams
{
float l_intr_p[4]; //[fx,fy,cx,cy]
float r_intr_p[4]; //[fx,fy,cx,cy]
float r2l_r[9]; //[r00,r01,r02;r10,r11,r12;r20,r21,r22]
float r2l_t[3]; //[t1,t2,t3]
float k[5]; //[k1,k2,k3,p1,p2]
int is_mirror;
}OBCameraParams;
OBCameraParams m_CamParams;
int dataSize = sizeof(OBCameraParams);
g_Device.getProperty(openni::OBEXTENSION_ID_CAM_PARAMS, (uint8_t
*)&m_CamParams, &dataSize);
1
2
3
4
5
6
7
8
9
10
11
12
13
int gain = 0;
int dataSize = 4;
g_Device.getProperty(openni::OBEXTENSION_ID_IR_GAIN, (uint8_t*)&gain,
&dataSize);
printf("ir gain value : 0x%x\n", gain);
1
2
3
4
9. 获取红外曝光值
10. 设置红外曝光值
int gain = 0;
int dataSize = 4;
g_Device.getProperty(openni::OBEXTENSION_ID_IR_GAIN, (uint8_t *)&gain,
&dataSize);
printf("ir gain value : 0x%x\n", gain);
gain++;
g_Device.setProperty(openni::OBEXTENSION_ID_IR_GAIN, (uint8_t *)&gain,
dataSize);
1
2
3
4
5
6
int exposure = 0;
int dataSize = 4;
g_Device.getProperty(openni::OBEXTENSION_ID_IR_EXP, (uint8_t*)&exposure,
&dataSize);
printf("ir exposure value : 0x%x\n", exposure);
1
2
3
4
int exposure = 0;
int dataSize = 4;
g_Device.getProperty(openni::OBEXTENSION_ID_IR_EXP, (uint8_t *)&exposure,
&dataSize);
printf("ir exposure value : 0x%x\n", exposure);
exposure += 256;
g_Device.setProperty(openni::OBEXTENSION_ID_IR_EXP, (uint8_t *)&exposure,
dataSize);
1
2
3
4
5
6
11. 红外相机切换
此功能仅适用于Astra 双目系列。
需要引入头文件PS1080.h,对XN_MODULE_PROPERTY_SWITCH_IR属性进行设置。
12. 激光保护
需要重新插拔3D传感器才能生效(除了Astra Stereo S U3)。
#include <PS1080.h>
…
int camera = 0; // 0: left; 1: right;
int dataSize = 4;
g_Device.setProperty(XN_MODULE_PROPERTY_SWITCH_IR, (uint8_t*)& camera,
dataSize)
1
2
3
4
5
13. 激光开关
14. 泛光灯开关(可选)
需要引入头文件PS1080.h,对XN_MODULE_PROPERTY_IRFLOOD_STATE属性进行设置。
int dataSize = 4;
int ldp_en = enable;
g_Device.setProperty(openni::OBEXTENSION_ID_LDP_EN, (uint8_t *)&ldp_en,
dataSize);
// For Astra Stereo S (U3) only, include PS1080.h first
// g_Device.setProperty(XN_MODULE_PROPERTY_LDP_ENABLE, (uint8_t *)&ldp_en,
dataSize);
1
2
3
4
5
int dataSize = 4;
int laser_en = enable; // 0: disable, 1: enable
g_Device.setProperty(openni::OBEXTENSION_ID_LASER_EN, (uint8_t *)&laser_en,
dataSize);
1
2
3
15. 彩色相机自动曝光
16. 设置彩色相机曝光值
#include <PS1080.h>
…
int dataSize = 4;
int ir_flood_en = enable; // 0: disable, 1: enable
g_Device.setProperty(XN_MODULE_PROPERTY_IRFLOOD_STATE, (uint8_t
*)&ir_flood_en, dataSize);
1
2
3
4
5
Openni::VideoStream g_ColorStream; // Generate variable for Color Video
Stream
g_ColorStream.getCameraSettings()>setAutoWhiteBalanceEnabled(
!g_ColorStream.getCameraSettings()->getAutoWhiteBalanceEnabled());
1
2
3
17. 彩色相机自动曝光 (UVC模式)
AstraPro和Astra Embedded S产品中彩色相机使用的是UVC模式,本例中通过Open CV来控制。
18. 设置彩色相机曝光值 (UVC模式)
Openni::VideoStream g_ColorStream; // Generate variable for Color Video
Stream
int exposure = 10;
g_ColorStream.getCameraSettings()->setExposure(exposure);
1
2
3
double auto_exposure_en = enable; // 0: disable, 1: enable
g_Capture.set(CV_CAP_PROP_AUTO_EXPOSURE, enable);
1
2
double exposure = 10.0;
g_Capture.set(CV_CAP_PROP_EXPOSURE, exposure);
1
2
19. 设置彩色相机自动白平衡
20. 获取彩色相机增益
21. 设置彩色相机增益
Openni::VideoStream g_ColorStream; // Generate variable for Color Video
Stream
bool state = false;
g_ColorStream.getCameraSettings()->setAutoWhiteBalanceEnabled (state);
1
2
3
Openni::VideoStream g_ColorStream; // Generate variable for Color Video
Stream
int gain;
gain = g_ColorStream.getCameraSettings()->getGain();
1
2
3
22. 多相机支持
OrbbecViewer支持同时打开多个相机(最多4个)。 用户选择需要工作的相机来配置同时工作的相机。此外用户可以在所选相机窗口内的不同数据流之间切换。
Openni::VideoStream g_ColorStream; // Generate variable for Color Video
Stream
int gain = 1000;
g_ColorStream.getCameraSettings()->setGain(gain);
1
2
3
23. 代码示例
23.1 OpenNI2 相关代码
#include <OpenNI.h> // Include OpenNI2 library header
#include <PS1080.h>
int main(int argc, char** argv)
{
// Variable Declaration
openni::Status rc = openni::STATUS_OK;
openni::Device g_Device;
openni::VideoStream g_DepthStream;
const char* deviceURI = openni::ANY_DEVICE;
// Open Device
rc = g_Device.open(deviceURI);
rc = openni::OpenNI::initialize();
// Initialize OpenNI2
if (rc != openni::STATUS_OK)
{
printf("Device open failed:\n%s\n",
openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -1;
}
rc = g_DepthStream.create(g_Device, openni::SENSOR_DEPTH);
// Create Depth Stream
if (rc == openni::STATUS_OK)
{
rc = g_DepthStream.start();
// Start streaming Depth Stream
if (rc != openni::STATUS_OK)
{
printf("Couldn't start depth stream:\n%s\n",
openni::OpenNI::getExtendedError());
g_DepthStream.destroy();
// Destroy Depth Stream
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
23.2 OpenNI2 多相机代码
确保运行前至少有2个相机连接。
}
}
else
{
printf("Couldn't find depth stream:\n%s\n",
openni::OpenNI::getExtendedError());
}
/* Process the stream data here */
g_DepthStream.stop();
// Stop streaming Depth Stream
openni::OpenNI::shutdown();
return 0;
}
31
32
33
34
35
36
37
38
39
40
41
42
#include <OpenNI.h> // Include OpenNI2 library header
#include <PS1080.h>
int main(int argc, char** argv)
{
// Variable Declaration
openni::Status rc = openni::STATUS_OK;
openni::Device g_Device1, g_Device2;
openni::VideoStream g_DepthStream1, g_DepthStream2;
// Open Device
rc = g_Device.open(deviceURI);
rc = openni::OpenNI::initialize();
// Initialize OpenNI2
if (rc != openni::STATUS_OK)
{
printf("Device open failed:\n%s\n",
openni::OpenNI::getExtendedError());
return -1;
}
openni::Array<openni::DeviceInfo> deviceList;
openni::OpenNI::enumerateDevices(&deviceList);
const char* device1Uri;
const char* device2Uri;
if (deviceList.getSize() < 2)
{
printf("Missing devices\n");
openni::OpenNI::shutdown();
return -1;
}
device1Uri = deviceList[1].getUri();
device2Uri = deviceList[0].getUri();
rc = g_Device1.open(device1Uri);
if (rc != openni::STATUS_OK)
{
printf("Couldn't open device %s\n%s\n", device1Uri,
openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -2;
}
rc = g_Device2.open(device2Uri);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
if (rc != openni::STATUS_OK)
{
printf("Couldn't open device %s\n%s\n", device2Uri,
openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -2;
}
rc = g_DepthStream1.create(g_Device1, openni::SENSOR_DEPTH);
// Create Depth Stream 1
if (rc != openni::STATUS_OK)
{
printf("Couldn't create stream %d on device %s\n%s\n",
openni::SENSOR_DEPTH, device1Uri, openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -3;
}
rc = g_DepthStream2.create(g_Device2, openni::SENSOR_DEPTH);
// Create Depth Stream 2
if (rc != openni::STATUS_OK)
{
printf("Couldn't create stream %d on device %s\n%s\n",
openni::SENSOR_DEPTH, device2Uri, openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -3;
}
rc = g_DepthStream1.start();
// Start streaming Depth Stream 1
if (rc != openni::STATUS_OK)
{
printf("Couldn't start stream %d on device %s\n%s\n",
openni::SENSOR_DEPTH, device1Uri, openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -4;
}
rc = g_DepthStream2.start();
// Start streaming Depth Stream 2
if (rc != openni::STATUS_OK)
{
printf("Couldn't start stream %d on device %s\n%s\n",
openni::SENSOR_DEPTH, device2Uri, openni::OpenNI::getExtendedError());
openni::OpenNI::shutdown();
return -4;
}
if (!g_DepthStream1.isValid() && !g_DepthStream2.isValid())
{
printf("SimpleViewer: No valid streams. Exiting\n");
openni::OpenNI::shutdown();
return -5;
}
/* Process the stream data here */
g_DepthStream1.stop();
g_DepthStream2.stop();
openni::OpenNI::shutdown();
return 0;
}
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
23.3 OpenCV 相关代码
#include <opencv2/opencv.hpp>
int main(int argc, char** argv)
{
// Variable Declaration
Cv::VideoCapture g_Capture(0);
// Open the default camera with constructor
cv::Mat g_ColorFrame;
// OpenCV Mat to hold the frames
if (!g_Capture.isOpened())
// Check if opening succeeded
return -1;
g_Capture.set(CV_CAP_PROP_FRAME_WIDTH, 640.0);
// Set frame width
g_Capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480.0);
// Set frame height
g_Capture.set(CV_CAP_PROP_FPS, 30.0);
// Set FPS
g_Capture.set(CV_CAP_PROP_AUTO_EXPOSURE, 0.0);
// Turn Auto Exposure off
g_Capture >> g_ColorFrame;
// Get a frame from camera
g_Capture.release();
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24