为什么做网站特效用用插件,微网站建设及开发,搜索服务公司,简洁文章类织梦网站模板一、信息获取
1、官网
用于了解产品信息
http://www.orbbec.com.cn/sys/37.html 2、开发者社区
咨询问题下载开发部https://developer.orbbec.com.cn/ 二 、windowvs19
1、相机型号
orbbec_astro_pro
根据对应的型号找到需要的包工具 踩坑1#xff0c;因为这个相机型号…一、信息获取
1、官网
用于了解产品信息
http://www.orbbec.com.cn/sys/37.html 2、开发者社区
咨询问题下载开发部https://developer.orbbec.com.cn/ 二 、windowvs19
1、相机型号
orbbec_astro_pro
根据对应的型号找到需要的包工具 踩坑1因为这个相机型号只能使用OpenNI2 SDK库进行开发orbbec SDk使用的话 会出现以下问题 2、使用步骤
1驱动安装
下载驱动双击
b工具安装 作用
a.用于快速查看相机是否安装正确;
b.可以可视化调整参数和显示效果 3OpenNI2 SDK 安装
可以直接按照官方的开发手册安装
踩坑2但是执行时仍然出现运行不了等问题
4在开发包自带的环境下开发
踩坑3:环境下配置了opencv版本比较多导致字符串类型的数据乱码 3、自己开发
1建立项目
2配置opencv 头文件dll ,lib
3) 配置OpenNI2 SDK 头文件 dlllib
4构建自己的代码 5执行效果 6数据保存 三、代码编写 1 #includeOpenNI.h
2 #includeiostream
3 #includeopencv2/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(Couldnt 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(Couldnt 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(Couldnt 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(Couldnt 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(Couldnt start the ir stream\n%s\n, OpenNI::getExtendedErro 85 }86 //创建数据帧
87 VideoFrameRef ir_frame;
88 cv::Mat ir_matcv::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 }