Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vpRealSense2::getProductLine() #1371

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/sensor/include/visp3/sensor/vpRealSense2.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ class VISP_EXPORT vpRealSense2

std::string getProductLine();

std::string getSensorInfo();

vpHomogeneousMatrix getTransformation(const rs2_stream &from, const rs2_stream &to, int from_index = -1) const;

bool open(const rs2::config &cfg = rs2::config());
Expand Down
48 changes: 33 additions & 15 deletions modules/sensor/src/rgb-depth/realsense/vpRealSense2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,21 +1419,23 @@ bool vpRealSense2::open(const rs2::config &cfg, std::function<void(rs2::frame)>
std::string vpRealSense2::getProductLine()
{
#if (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
if (!m_init) { // If pipe is not already created, create it. Otherwise, we have already determined the product line
rs2::pipeline *pipe = new rs2::pipeline;
rs2::pipeline_profile *pipelineProfile = new rs2::pipeline_profile;
*pipelineProfile = pipe->start();

rs2::device dev = pipelineProfile->get_device();

#if (RS2_API_VERSION > ((2 * 10000) + (31 * 100) + 0))
// Query device product line D400/SR300/L500/T200
m_product_line = dev.get_info(RS2_CAMERA_INFO_PRODUCT_LINE);
#endif

pipe->stop();
delete pipe;
delete pipelineProfile;
// With previous code, example/device/framegrabber/grabRealSense2.cpp does not work with D455
// Error: Frame didn't arrive within 15000
// Following code from:
// https://github.com/IntelRealSense/librealsense/blob/4673a37d981164af8eeb8e296e430fc1427e008d/unit-tests/live/memory/test-extrinsics.cpp#L119

// Reset product line info
m_product_line = "unknown";

rs2::context ctx;
auto list = ctx.query_devices();
if (list.size() > 0) {
// Only one plugged sensor supported
auto dev = list.front();
auto sensors = dev.query_sensors();
if (dev.supports(RS2_CAMERA_INFO_PRODUCT_LINE)) {
m_product_line = dev.get_info(RS2_CAMERA_INFO_PRODUCT_LINE);
}
}

return m_product_line;
Expand All @@ -1442,6 +1444,22 @@ std::string vpRealSense2::getProductLine()
#endif
}

/*!
* Alias for the &operator<< operator.
* Return sensor information such as:
* - device info
* - supported options
* - stream profiles
* - intrinsics / extrinsics
* - [...]
*/
std::string vpRealSense2::getSensorInfo()
{
std::ostringstream oss;
oss << *this;
return oss.str();;
}

namespace
{
// Helper functions to print information about the RealSense device
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int main()

chrono.stop();
time_vector.push_back(chrono.getDurationMs());
if (cv::waitKey(5) == 27) {
if (cv::waitKey(5) == 27 || cv::waitKey(5) == 113) { // Esc or q
break;
}
}
Expand Down
Loading