10
10
namespace cv
11
11
{
12
12
13
- VideoCapture_LibRealsense::VideoCapture_LibRealsense (int index )
13
+ VideoCapture_LibRealsense::VideoCapture_LibRealsense (int ) : mAlign (RS2_STREAM_COLOR )
14
14
{
15
15
try
16
16
{
17
- mDev = mContext . get_device ( index ) ;
18
- // Configure all streams to run at VGA resolution at 60 frames per second
19
- mDev -> enable_stream (rs::stream::depth , 640 , 480 , rs::format::z16, 60 );
20
- mDev -> enable_stream (rs::stream::color , 640 , 480 , rs::format::bgr8, 60 );
21
- mDev -> enable_stream (rs::stream::infrared , 640 , 480 , rs::format::y8, 60 );
22
- mDev -> start ();
17
+ rs2::config config ;
18
+ // Configure all streams to run at VGA resolution at default fps
19
+ config. enable_stream (RS2_STREAM_DEPTH , 640 , 480 , RS2_FORMAT_Z16 );
20
+ config. enable_stream (RS2_STREAM_COLOR , 640 , 480 , RS2_FORMAT_BGR8 );
21
+ config. enable_stream (RS2_STREAM_INFRARED , 640 , 480 , RS2_FORMAT_Y8 );
22
+ mPipe . start ();
23
23
}
24
- catch (rs ::error&)
24
+ catch (const rs2 ::error&)
25
25
{
26
- mDev = nullptr ;
27
26
}
28
27
}
29
28
VideoCapture_LibRealsense::~VideoCapture_LibRealsense (){}
@@ -32,8 +31,8 @@ double VideoCapture_LibRealsense::getProperty(int prop) const
32
31
{
33
32
double propValue = 0 ;
34
33
35
- if (prop == CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE)
36
- return mDev -> get_depth_scale ();
34
+ if (prop == CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE)
35
+ return mPipe . get_active_profile (). get_device (). first <rs2::depth_sensor>(). get_depth_scale ();
37
36
38
37
return propValue;
39
38
}
@@ -50,9 +49,9 @@ bool VideoCapture_LibRealsense::grabFrame()
50
49
51
50
try
52
51
{
53
- mDev -> wait_for_frames ();
52
+ mData = mAlign . process ( mPipe . wait_for_frames () );
54
53
}
55
- catch (rs ::error&)
54
+ catch (const rs2 ::error&)
56
55
{
57
56
return false ;
58
57
}
@@ -61,20 +60,20 @@ bool VideoCapture_LibRealsense::grabFrame()
61
60
}
62
61
bool VideoCapture_LibRealsense::retrieveFrame (int outputType, cv::OutputArray frame)
63
62
{
64
- rs::stream stream ;
63
+ rs2::video_frame _frame ( nullptr ) ;
65
64
int type;
66
65
switch (outputType)
67
66
{
68
67
case CAP_INTELPERC_DEPTH_MAP:
69
- stream = rs::stream::depth_aligned_to_color ;
68
+ _frame = mData . get_depth_frame (). as <rs2::video_frame>() ;
70
69
type = CV_16UC1;
71
70
break ;
72
71
case CAP_INTELPERC_IR_MAP:
73
- stream = rs::stream::infrared ;
72
+ _frame = mData . get_infrared_frame () ;
74
73
type = CV_8UC1;
75
74
break ;
76
75
case CAP_INTELPERC_IMAGE:
77
- stream = rs::stream::color ;
76
+ _frame = mData . get_color_frame () ;
78
77
type = CV_8UC3;
79
78
break ;
80
79
default :
@@ -84,10 +83,10 @@ bool VideoCapture_LibRealsense::retrieveFrame(int outputType, cv::OutputArray fr
84
83
try
85
84
{
86
85
// we copy the data straight away, so const_cast should be fine
87
- void * data = const_cast <void *>(mDev -> get_frame_data (stream ));
88
- Mat (mDev -> get_stream_height (stream ), mDev -> get_stream_width (stream ), type, data).copyTo (frame);
86
+ void * data = const_cast <void *>(_frame. get_data ( ));
87
+ Mat (_frame. get_height ( ), _frame. get_width ( ), type, data, _frame. get_stride_in_bytes () ).copyTo (frame);
89
88
}
90
- catch (rs ::error&)
89
+ catch (const rs2 ::error&)
91
90
{
92
91
return false ;
93
92
}
@@ -101,7 +100,7 @@ int VideoCapture_LibRealsense::getCaptureDomain()
101
100
102
101
bool VideoCapture_LibRealsense::isOpened () const
103
102
{
104
- return mDev && mDev -> is_streaming ( );
103
+ return bool (std::shared_ptr<rs2_pipeline>( mPipe ) );
105
104
}
106
105
107
106
}
0 commit comments