Skip to content

Commit 09b3dcb

Browse files
UnaNancyOwenalalek
authored andcommitted
Merge pull request opencv#13341 from UnaNancyOwen:fix_librealsense
* videoio(librealsense): fix pipeline start with config fix to apply pipeline settings by passing config to start. * videoio(librealsense): add support get props add support get some props.
1 parent ef42baf commit 09b3dcb

File tree

3 files changed

+144
-6
lines changed

3 files changed

+144
-6
lines changed

modules/videoio/include/opencv2/videoio.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ enum { CAP_PROP_INTELPERC_PROFILE_COUNT = 11001,
526526
//! Intel Perceptual Streams
527527
enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29,
528528
CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28,
529-
CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR
529+
CAP_INTELPERC_IR_GENERATOR = 1 << 27,
530+
CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR + CAP_INTELPERC_IR_GENERATOR
530531
};
531532

532533
enum { CAP_INTELPERC_DEPTH_MAP = 0, //!< Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth.

modules/videoio/src/cap_librealsense.cpp

+137-5
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,155 @@ VideoCapture_LibRealsense::VideoCapture_LibRealsense(int) : mAlign(RS2_STREAM_CO
1919
config.enable_stream(RS2_STREAM_DEPTH, 640, 480, RS2_FORMAT_Z16);
2020
config.enable_stream(RS2_STREAM_COLOR, 640, 480, RS2_FORMAT_BGR8);
2121
config.enable_stream(RS2_STREAM_INFRARED, 640, 480, RS2_FORMAT_Y8);
22-
mPipe.start();
22+
mPipe.start(config);
2323
}
2424
catch (const rs2::error&)
2525
{
2626
}
2727
}
2828
VideoCapture_LibRealsense::~VideoCapture_LibRealsense(){}
2929

30-
double VideoCapture_LibRealsense::getProperty(int prop) const
30+
double VideoCapture_LibRealsense::getProperty(int propIdx) const
3131
{
32-
double propValue = 0;
32+
double propValue = 0.0;
3333

34-
if (prop == CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE)
35-
return mPipe.get_active_profile().get_device().first<rs2::depth_sensor>().get_depth_scale();
34+
const int purePropIdx = propIdx & ~CAP_INTELPERC_GENERATORS_MASK;
35+
if((propIdx & CAP_INTELPERC_GENERATORS_MASK) == CAP_INTELPERC_IMAGE_GENERATOR)
36+
{
37+
propValue = getImageGeneratorProperty(purePropIdx);
38+
}
39+
else if((propIdx & CAP_INTELPERC_GENERATORS_MASK) == CAP_INTELPERC_DEPTH_GENERATOR)
40+
{
41+
propValue = getDepthGeneratorProperty(purePropIdx);
42+
}
43+
else if((propIdx & CAP_INTELPERC_GENERATORS_MASK) == CAP_INTELPERC_IR_GENERATOR)
44+
{
45+
propValue = getIrGeneratorProperty(purePropIdx);
46+
}
47+
else
48+
{
49+
propValue = getCommonProperty(purePropIdx);
50+
}
3651

3752
return propValue;
3853
}
54+
55+
double VideoCapture_LibRealsense::getImageGeneratorProperty(int propIdx) const
56+
{
57+
double propValue = 0.0;
58+
const rs2::video_stream_profile profile = mPipe.get_active_profile().get_stream(RS2_STREAM_COLOR).as<rs2::video_stream_profile>();
59+
if(!profile)
60+
{
61+
return propValue;
62+
}
63+
64+
switch(propIdx)
65+
{
66+
case CAP_PROP_FRAME_WIDTH:
67+
propValue = static_cast<double>(profile.width());
68+
break;
69+
case CAP_PROP_FRAME_HEIGHT:
70+
propValue = static_cast<double>(profile.height());
71+
break;
72+
case CAP_PROP_FPS:
73+
propValue = static_cast<double>(profile.fps());
74+
break;
75+
}
76+
77+
return propValue;
78+
}
79+
80+
double VideoCapture_LibRealsense::getDepthGeneratorProperty(int propIdx) const
81+
{
82+
double propValue = 0.0;
83+
const rs2::video_stream_profile profile = mPipe.get_active_profile().get_stream(RS2_STREAM_DEPTH).as<rs2::video_stream_profile>();
84+
const rs2::depth_sensor sensor = mPipe.get_active_profile().get_device().first<rs2::depth_sensor>();
85+
if(!profile || !sensor)
86+
{
87+
return propValue;
88+
}
89+
90+
switch(propIdx)
91+
{
92+
case CAP_PROP_FRAME_WIDTH:
93+
propValue = static_cast<double>(profile.width());
94+
break;
95+
case CAP_PROP_FRAME_HEIGHT:
96+
propValue = static_cast<double>(profile.height());
97+
break;
98+
case CAP_PROP_FPS:
99+
propValue = static_cast<double>(profile.fps());
100+
break;
101+
case CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE:
102+
propValue = static_cast<double>(sensor.get_depth_scale());
103+
break;
104+
case CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ:
105+
propValue = static_cast<double>(profile.get_intrinsics().fx);
106+
break;
107+
case CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT:
108+
propValue = static_cast<double>(profile.get_intrinsics().fy);
109+
break;
110+
}
111+
112+
return propValue;
113+
}
114+
115+
double VideoCapture_LibRealsense::getIrGeneratorProperty(int propIdx) const
116+
{
117+
double propValue = 0.0;
118+
const rs2::video_stream_profile profile = mPipe.get_active_profile().get_stream(RS2_STREAM_INFRARED).as<rs2::video_stream_profile>();
119+
if(!profile)
120+
{
121+
return propValue;
122+
}
123+
124+
switch(propIdx)
125+
{
126+
case CAP_PROP_FRAME_WIDTH:
127+
propValue = static_cast<double>(profile.width());
128+
break;
129+
case CAP_PROP_FRAME_HEIGHT:
130+
propValue = static_cast<double>(profile.height());
131+
break;
132+
case CAP_PROP_FPS:
133+
propValue = static_cast<double>(profile.fps());
134+
break;
135+
}
136+
137+
return propValue;
138+
}
139+
140+
double VideoCapture_LibRealsense::getCommonProperty(int propIdx) const
141+
{
142+
double propValue = 0.0;
143+
const rs2::video_stream_profile profile = mPipe.get_active_profile().get_stream(RS2_STREAM_DEPTH).as<rs2::video_stream_profile>();
144+
const rs2::depth_sensor sensor = mPipe.get_active_profile().get_device().first<rs2::depth_sensor>();
145+
if(!profile || !sensor)
146+
{
147+
return propValue;
148+
}
149+
150+
switch(propIdx)
151+
{
152+
case CAP_PROP_FRAME_WIDTH:
153+
case CAP_PROP_FRAME_HEIGHT:
154+
case CAP_PROP_FPS:
155+
propValue = getDepthGeneratorProperty(propIdx);
156+
break;
157+
case CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE:
158+
propValue = static_cast<double>(sensor.get_depth_scale());
159+
break;
160+
case CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ:
161+
propValue = static_cast<double>(profile.get_intrinsics().fx);
162+
break;
163+
case CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT:
164+
propValue = static_cast<double>(profile.get_intrinsics().fy);
165+
break;
166+
}
167+
168+
return propValue;
169+
}
170+
39171
bool VideoCapture_LibRealsense::setProperty(int, double)
40172
{
41173
bool isSet = false;

modules/videoio/src/cap_librealsense.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class VideoCapture_LibRealsense : public IVideoCapture
2929
rs2::pipeline mPipe;
3030
rs2::frameset mData;
3131
rs2::align mAlign;
32+
33+
double getDepthGeneratorProperty(int propIdx) const;
34+
double getImageGeneratorProperty(int propIdx) const;
35+
double getIrGeneratorProperty(int propIdx) const;
36+
double getCommonProperty(int propIdx) const;
3237
};
3338

3439
}

0 commit comments

Comments
 (0)