一、信息獲取
1、官網
用于了解產品信息
http://www.orbbec.com.cn/sys/37.html
2、開發者社區
- 咨詢問題
- 下載開發部https://developer.orbbec.com.cn/
二 、window+vs19
1、相機型號
orbbec_astro_pro
根據對應的型號找到需要的包工具
踩坑1,因為這個相機型號只能使用OpenNI2 SDK庫進行開發,orbbec SDk使用的話, 會出現以下問題:
2、使用步驟
1)驅動安裝
下載驅動,雙擊
b)工具安裝
作用:
a.用于快速查看相機是否安裝正確;
b.可以可視化調整參數和顯示效果
3)OpenNI2 SDK 安裝
可以直接按照官方的開發手冊安裝
踩坑2:但是執行時仍然出現運行不了等問題
4)在開發包自帶的環境下開發
踩坑3:環境下配置了opencv版本比較多,導致,字符串類型的數據亂碼
3、自己開發
1)建立項目
2)配置opencv 頭文件,dll ,lib
3) 配置OpenNI2 SDK 頭文件??? dll,lib
4)構建自己的代碼
5)執行效果
6)數據保存
三、代碼編寫
1 #include<OpenNI.h>
2 #include<iostream>
3 #include<opencv2/opencv.hpp> 4
5 using namespace openni; 6
7 int main() 8 {
9 //1、設備初始化
10 Status sc = OpenNI::initialize();
11 if (sc != STATUS_OK) 12 {
13 printf("Initialize failed\n%s\n", OpenNI::getExtendedError());
14 // return 1; 15 }
16 //2、打開設備
17 Device device;
18 sc = device.open(ANY_DEVICE);
19 if (sc != STATUS_OK) 20 {
21 printf("Couldn't open device\n%s\n", OpenNI::getExtendedError());
22 return 2; 23 }
24 //3、創建深度流
25 VideoStream depthStream;
26 if (device.getSensorInfo(SENSOR_DEPTH) != NULL) 27 {
28 sc = depthStream.create(device, SENSOR_DEPTH);
29 if (sc != STATUS_OK)
30 {
31 printf("Couldn't create depth stream\n%s\n", OpenNI::getExtended 32 }
33 }
34 //配置深度流的模式
35 VideoMode depthMode;
36 depthMode.setResolution(640, 480);
37 depthMode.setPixelFormat(PIXEL_FORMAT_DEPTH_1_MM);
38 depthMode.setFps(30);
39 depthStream.setVideoMode(depthMode);
40 // 打開深度流
41 sc = depthStream.start();
42 if (sc != STATUS_OK)43 {
44
45 }printf("Couldn't start the depth stream\n%s\n", OpenNI::getExtendedE46 //創建數據幀
47 VideoFrameRef depthframe;
48 cv::Mat depth_mat= cv::Mat::zeros(cv::Size(640, 480), CV_8UC1);
49 cv::namedWindow("depth_win", cv::WINDOW_AUTOSIZE);
50 //創建寫入視頻文件
51 cv::VideoWriter w_depth;
52 //指定保存文件位置,編碼器,幀率,寬高
53 w_depth.open("depth.mp4", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), 3 54
55 //創建偽彩色
56 cv::Mat falseColorsMap_mat;
57 cv::namedWindow("falseColorsMap_win", cv::WINDOW_AUTOSIZE);
58 //創建寫入視頻文件
59 cv::VideoWriter w_falseColorsMap;
60 //指定保存文件位置,編碼器,幀率,寬高
61 w_falseColorsMap.open("depth.mp4", cv::VideoWriter::fourcc('D', 'I', 'V' 62
63
64 //3.1 創建近紅外流
65 VideoStream ir_Stream;
66 if (device.getSensorInfo(SENSOR_IR)!=NULL) 67 {
68 sc = ir_Stream.create(device, SENSOR_IR);
69 if (sc != STATUS_OK)
70 {
71 printf("Couldn't create depth stream\n%s\n", OpenNI::getExtended 72 }
73 }
74 //配置近紅外的模式
75 VideoMode ir_Mode;
76 ir_Mode.setResolution(640, 480);
77 ir_Mode.setFps(30);
78 ir_Stream.setVideoMode(ir_Mode); 79
80 // 打開近紅外流
81 sc = ir_Stream.start();
82 if (sc != STATUS_OK) 83 {
84 printf("Couldn't start the ir stream\n%s\n", OpenNI::getExtendedErro 85 }86 //創建數據幀
87 VideoFrameRef ir_frame;
88 cv::Mat ir_mat=cv::Mat::zeros(cv::Size(640, 480), CV_8UC1);;
89 cv::namedWindow("ir_win", cv::WINDOW_AUTOSIZE);
90 //創建寫入視頻文件
91 cv::VideoWriter w_ir;
92 //指定保存文件位置,編碼器,幀率,寬高
93 w_ir.open("ir.mp4", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), 30, cv: 94
95 //3.2 創建彩色圖流
96 cv::VideoCapture cap;
97 cap.open(1);
98 if (!cap.isOpened()) 99 {
100 printf("could not load video data...\n");
101 return -1;
102 }
103 int frames = cap.get(cv::CAP_PROP_FRAME_COUNT);
104 double fps = cap.get(cv::CAP_PROP_FPS);//獲取每針視頻的頻率
105 // 獲取幀的視頻寬度,視頻高度
106 cv::Size size = cv::Size(cap.get(cv::CAP_PROP_FRAME_WIDTH), cap.get(cv::
107 std::cout << frames << std::endl;
108 std::cout << fps << std::endl;
109 std::cout << size << std::endl;
110 cv::Mat color_mat;
111 cv::namedWindow("color_win", cv::WINDOW_AUTOSIZE);
112 //創建寫入視頻文件
113 cv::VideoWriter w_color;
114 //指定保存文件位置,編碼器,幀率,寬高
115 w_color.open("color.mp4", cv::VideoWriter::fourcc('D', 'I', 'V', 'X'), 3 116
117
118 while (true)
119 {
120 //4 創建深度流指針
121 VideoStream* p_depth_stream = &depthStream;
122 int changedDepthStreamDummy;
123 //等待一幀
124 Status sc_depth = OpenNI::waitForAnyStream(&p_depth_stream, 1, &chan
125 if (sc_depth != STATUS_OK)
126 {
127 continue;
128 }129 //獲取深度幀數據
130 sc_depth = depthStream.readFrame(&depthframe);
131 if (sc_depth == STATUS_OK)
132 {
133 auto depth = depthframe.getData();
134 auto depthWidth = depthframe.getWidth();
135 auto depthHeight = depthframe.getHeight();
136 int len = depthframe.getDataSize();
137 //std::cout << len << std::endl;
138 //處理并渲染深度幀數據
139 cv::Mat rawMat(depthHeight, depthWidth, CV_16UC1, (void*)depth); 140
141 cv::normalize(rawMat, depth_mat, 0, 255, cv::NORM_MINMAX,CV_8UC1
142 double min;
143 double max;
144 int maxIDX;
145 int minIDX;
146 cv::minMaxIdx(rawMat, &min, &max, &minIDX, &maxIDX);
147 float scale = 255.0 / (max - min);
148 rawMat.convertTo(depth_mat, CV_8UC1, scale, -min * scale);
149 cv::imshow("depth_win", depth_mat);
150 w_depth << depth_mat; 151
152 applyColorMap(depth_mat, falseColorsMap_mat, cv::COLORMAP_JET);
153 cv::imshow("falseColorsMap_win", falseColorsMap_mat);
154 w_depth << falseColorsMap_mat;
155 }
156
157 //4.1創建近紅外流指針
158 VideoStream* p_ir_stream = &ir_Stream;
159 int changedIrStreamDummy;
160 //等待一幀
161 Status sc_ir = OpenNI::waitForAnyStream(&p_ir_stream, 1, &changedIrS
162 if (sc_ir != STATUS_OK)
163 {
164 continue;
165 }
166 //獲取近紅外數據
167 sc_ir = ir_Stream.readFrame(&ir_frame);
168 if (sc_ir == STATUS_OK)
169 {
170 auto depth = ir_frame.getData();
171 auto ir_Width = ir_frame.getWidth();172
173
174
175 auto ir_Height = ir_frame.getHeight();//處理并渲染深度幀數據
cv::Mat rawMat(ir_Height, ir_Width, CV_16UC1, (void*)depth);
176 cv::normalize(rawMat, ir_mat, 0, 255, cv::NORM_MINMAX, CV_8UC1);
177 //rawMat.convertTo(ir_mat, CV_8UC1);
178 cv::imshow("ir_win", ir_mat);
179 w_ir << ir_mat;
180 }
181
182 //4.2讀取彩色流
183 cap >> color_mat;
184 if (color_mat.empty())
185 {
186 break;
187 }
188 cv::imshow("color_win", color_mat);
189 w_color << color_mat;
190 //在視頻播放期間按鍵退出
191 if (cv::waitKey(33) >= 0) break;
192 }
193
194 depthStream.stop();
195 depthStream.destroy();
196 ir_Stream.stop();
197 ir_Stream.destroy();
198 device.close();
199 OpenNI::shutdown();
200
201 cap.release();
202 return 0;
203 }