@@ -9,8 +9,8 @@ Using Orbbec Astra 3D cameras {#tutorial_orbbec_astra}
9
9
10
10
This tutorial is devoted to the Astra Series of Orbbec 3D cameras (https://orbbec3d.com/product-astra-pro/ ).
11
11
That cameras have a depth sensor in addition to a common color sensor. The depth sensors can be read using
12
- the OpenNI interface with @ref cv::VideoCapture class. The video stream is provided through the regular camera
13
- interface.
12
+ the open source OpenNI API with @ref cv::VideoCapture class. The video stream is provided through the regular
13
+ camera interface.
14
14
15
15
### Installation Instructions
16
16
@@ -70,15 +70,20 @@ In order to use a depth sensor with OpenCV you should do the following steps:
70
70
71
71
### Code
72
72
73
- To get both depth and color frames, two @ref cv::VideoCapture objects should be created:
73
+ The Astra Pro camera has two sensors -- a depth sensor and a color sensor. The depth sensors
74
+ can be read using the OpenNI interface with @ref cv::VideoCapture class. The video stream is
75
+ not available through OpenNI API and is only provided through the regular camera interface.
76
+ So, to get both depth and color frames, two @ref cv::VideoCapture objects should be created:
74
77
75
78
@snippetlineno samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp Open streams
76
79
77
- The first object will use the regular Video4Linux2 interface to access the color sensor. The second one
80
+ The first object will use the Video4Linux2 interface to access the color sensor. The second one
78
81
is using OpenNI2 API to retrieve depth data.
79
82
80
- Before using the created VideoCapture objects you may want to setup stream parameters by setting
81
- objects' properties. The most important parameters are frame width, frame height and fps:
83
+ Before using the created VideoCapture objects you may want to set up stream parameters by setting
84
+ objects' properties. The most important parameters are frame width, frame height and fps.
85
+ For this example, we’ll configure width and height of both streams to VGA resolution as that’s
86
+ the maximum resolution available for both sensors and we’d like both stream parameters to be the same:
82
87
83
88
@snippetlineno samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp Setup streams
84
89
@@ -113,8 +118,9 @@ After the VideoCapture objects are set up you can start reading frames from them
113
118
to avoid one stream blocking while another stream is being read. VideoCapture is not a
114
119
thread-safe class, so you need to be careful to avoid any possible deadlocks or data races.
115
120
116
- Example implementation that gets frames from each sensor in a new thread and stores them
117
- in a list along with their timestamps:
121
+ As there are two video sources that should be read simultaneously, it’s necessary to create two
122
+ threads to avoid blocking. Example implementation that gets frames from each sensor in a new thread
123
+ and stores them in a list along with their timestamps:
118
124
119
125
@snippetlineno samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp Read streams
120
126
@@ -130,17 +136,24 @@ VideoCapture can retrieve the following data:
130
136
131
137
-# data given from the color sensor is a regular BGR image (CV_8UC3).
132
138
133
- When new data is available a reading thread notifies the main thread. A frame is stored in the
134
- ordered list -- the first frame is the latest one:
139
+ When new data are available a reading thread notifies the main thread using a condition variable.
140
+ A frame is stored in the ordered list -- the first frame is the latest one. As depth and color frames
141
+ are read from independent sources two video streams may become out of sync even when both streams
142
+ are set up for the same frame rate. A post-synchronization procedure can be applied to the streams
143
+ to combine depth and color frames into pairs. The sample code below demonstrates this procedure:
135
144
136
- @snippetlineno samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp Show color frame
145
+ @snippetlineno samples/cpp/tutorial_code/videoio/orbbec_astra/orbbec_astra.cpp Pair frames
137
146
138
- Depth frames can be picked the same way from the ` depthFrames ` list.
147
+ In the code snippet above the execution is blocked until there are some frames in both frame lists.
148
+ When there are new frames, their timestamps are being checked -- if they differ more than a half of
149
+ the frame period then one of the frames is dropped. If timestamps are close enough, then two frames
150
+ are paired. Now, we have two frames: one containing color information and another one -- depth information.
151
+ In the example above retrieved frames are simply shown with cv::imshow function, but you can insert
152
+ any other processing code here.
139
153
140
- After that, you'll have two frames: one containing color information and another one -- depth
141
- information. In the sample images below you can see the color frame and the depth frame showing
142
- the same scene. Looking at the color frame it's hard to distinguish plant leaves from leaves painted
143
- on a wall, but the depth data makes it easy.
154
+ In the sample images below you can see the color frame and the depth frame representing the same scene.
155
+ Looking at the color frame it's hard to distinguish plant leaves from leaves painted on a wall,
156
+ but the depth data makes it easy.
144
157
145
158
![ Color frame] ( images/astra_color.jpg )
146
159
![ Depth frame] ( images/astra_depth.png )
0 commit comments