奥比中光astra_pro相机使用记录

一、信息获取

1、官网

用于了解产品信息

http://www.orbbec.com.cn/sys/37.html

2、开发者社区

  1. 咨询问题
  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::getExtendedE
 
46	//创建数据帧
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	}	

相关推荐

  1. vue缩放使用

    2024-07-10 04:12:01       23 阅读
  2. OpenCV 单目相机平面标定

    2024-07-10 04:12:01       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 04:12:01       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 04:12:01       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 04:12:01       90 阅读
  4. Python语言-面向对象

    2024-07-10 04:12:01       98 阅读

热门阅读

  1. toString方法介绍

    2024-07-10 04:12:01       22 阅读
  2. LLM大语言模型知识点整理

    2024-07-10 04:12:01       24 阅读
  3. 使用Boost.Asio编写TCP通信程序框架(一)

    2024-07-10 04:12:01       42 阅读
  4. 导师好奇我为什么开发后端模版只花了一小时!

    2024-07-10 04:12:01       27 阅读
  5. android 7.0 tts文字转语音

    2024-07-10 04:12:01       24 阅读
  6. 离线升级docker中的某个镜像——以etcd为例

    2024-07-10 04:12:01       52 阅读
  7. 将pytorch 模型封装为c++ api 例子

    2024-07-10 04:12:01       34 阅读
  8. Rust: 关于Pin以及move前后分析

    2024-07-10 04:12:01       32 阅读
  9. LVS实验

    LVS实验

    2024-07-10 04:12:01      28 阅读