-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add RSSDK 2.0 (librealsense2) grabber #2214
Changes from all commits
22ef192
3c4ac27
f3b47cf
f5ced03
dfa2b7c
b8513c4
85974ad
3c4c73c
7df5e65
56754ee
2d3bdc6
0179fba
2f7b7a2
bc7e82e
2c42a0c
7be6219
4cf198d
8575522
f147759
4709f1f
9e09119
3f25e56
313e5f5
792ff4d
5e780b2
d294aff
5bc175b
8cf1d7e
6b88599
1bd2270
9c6d641
1831099
3f7a587
ebc9067
b8ffae8
75cf960
1a5db1f
bddc3bb
43756c3
d8a8923
c42a013
4be44f1
1528a3d
ed9e09f
312bc25
69ba109
65fc64d
131775c
b5a5e9c
36d3653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,6 +216,16 @@ macro(find_rssdk) | |
find_package(RSSDK) | ||
endmacro() | ||
|
||
macro(find_rssdk2) | ||
if(PCL_ALL_IN_ONE_INSTALLER) | ||
set(realsense2_DIR "${PCL_ROOT}/3rdParty/librealsense2/lib/cmake/realsense2" CACHE PATH "The directory containing realsense2Config.cmake") | ||
elseif(NOT realsense2_DIR) | ||
get_filename_component(realsense2_DIR "@REALSENSE2_INCLUDE_DIRS@" PATH) | ||
set(realsense2_DIR "${realsense2_DIR}/lib/cmake/realsense2" CACHE PATH "The directory containing realsense2Config.cmake") | ||
endif() | ||
find_package(RSSDK2) | ||
endmacro() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change for PCL All-in-one Installer. + macro(find_realsense2)
+ if(PCL_ALL_IN_ONE_INSTALLER)
+ set(realsense2_DIR "${PCL_ROOT}/3rdParty/librealsense2/lib/cmake/realsense2" CACHE PATH "The directory containing realsense2Config.cmake")
+ elseif(NOT realsense2_DIR)
+ get_filename_component(realsense2_DIR "@REALSENSE2_INCLUDE_DIRS@" PATH)
+ set(realsense2_DIR "${realsense2_DIR}/lib/cmake/realsense2" CACHE PATH "The directory containing realsense2Config.cmake")
+ endif(PCL_ALL_IN_ONE_INSTALLER)
+
+ find_package(realsense2)
+
+ if(realsense2_FOUND)
+ set(REALSENSE2_FOUND ${realsense2_FOUND})
+ set(REALSENSE2_INCLUDE_DIRS ${realsense_INCLUDE_DIR})
+ set(REALSENSE2_LIBRARIES ${realsense2_LIBRARY})
+ endif()
+ endmacro(find_realsense2) |
||
#remove this as soon as flann is shipped with FindFlann.cmake | ||
macro(find_flann) | ||
if(PCL_ALL_IN_ONE_INSTALLER) | ||
|
@@ -295,6 +305,8 @@ macro(find_external_library _component _lib _is_optional) | |
find_dssdk() | ||
elseif("${_lib}" STREQUAL "rssdk") | ||
find_rssdk() | ||
elseif("${_lib}" STREQUAL "rssdk2") | ||
find_rssdk2() | ||
elseif("${_lib}" STREQUAL "vtk") | ||
find_VTK() | ||
elseif("${_lib}" STREQUAL "libusb-1.0") | ||
|
@@ -645,7 +657,7 @@ endif() | |
pcl_remove_duplicate_libraries(PCL_COMPONENTS PCL_LIBRARIES) | ||
|
||
# Add 3rd party libraries, as user code might include our .HPP implementations | ||
list(APPEND PCL_LIBRARIES ${BOOST_LIBRARIES} ${QHULL_LIBRARIES} ${OPENNI_LIBRARIES} ${OPENNI2_LIBRARIES} ${ENSENSO_LIBRARIES} ${davidSDK_LIBRARIES} ${DSSDK_LIBRARIES} ${RSSDK_LIBRARIES} ${VTK_LIBRARIES}) | ||
list(APPEND PCL_LIBRARIES ${BOOST_LIBRARIES} ${QHULL_LIBRARIES} ${OPENNI_LIBRARIES} ${OPENNI2_LIBRARIES} ${ENSENSO_LIBRARIES} ${davidSDK_LIBRARIES} ${DSSDK_LIBRARIES} ${RSSDK_LIBRARIES} ${RSSDK2_LIBRARIES} ${VTK_LIBRARIES}) | ||
if (TARGET FLANN::FLANN) | ||
list(APPEND PCL_LIBRARIES FLANN::FLANN) | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
############################################################################### | ||
# Find Intel RealSense SDK 2.0 (librealsense) | ||
# | ||
# find_package(RSSDK2) | ||
# | ||
# Variables defined by this module: | ||
# | ||
# RSSDK2_FOUND True if RealSense SDK 2.0 was found | ||
# RSSDK2_INCLUDE_DIRS The location(s) of RealSense SDK 2.0 headers | ||
# RSSDK2_LIBRARIES Libraries needed to use RealSense SDK 2.0 | ||
|
||
find_package(realsense2) | ||
|
||
set(RSSDK2_FOUND ${realsense2_FOUND}) | ||
set(RSSDK2_INCLUDE_DIRS ${realsense2_INCLUDE_DIR}) | ||
set(RSSDK2_LIBRARIES ${realsense2_LIBRARY}) | ||
taketwo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if(RSSDK2_FOUND) | ||
message(STATUS "RealSense SDK 2 found (include: ${RSSDK2_INCLUDE_DIRS}, lib: ${RSSDK2_LIBRARIES}, version: ${realsense2_VERSION})") | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
/* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Point Cloud Library (PCL) - www.pointclouds.org | ||
* Copyright (c) 2018-, Open Perception, Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the copyright holder(s) nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
taketwo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <thread> | ||
#include <mutex> | ||
|
||
#include <pcl/io/boost.h> | ||
#include <pcl/io/grabber.h> | ||
#include <pcl/point_cloud.h> | ||
#include <pcl/point_types.h> | ||
|
||
#include <librealsense2/rs.hpp> | ||
|
||
namespace pcl | ||
{ | ||
|
||
/** \brief Grabber for Intel Realsense 2 SDK devices (D400 series) | ||
* \note Device width/height defaults to 424/240, the lowest resolutions for D400 devices. | ||
* \note Testing on the in_hand_scanner example we found the lower default resolution allowed the app to perform adequately. | ||
* \note Developers should use this resolution as a starting point and gradually increase to get the best results | ||
* \author Patrick Abadi <patrickabadi@gmail.com>, Daniel Packard <pack3754@gmail.com> | ||
* \ingroup io | ||
*/ | ||
class PCL_EXPORTS RealSense2Grabber : public pcl::Grabber | ||
{ | ||
public: | ||
/** \brief Constructor | ||
* \param[in] file_name_or_serial_number used for either loading bag file or specific device by serial number | ||
*/ | ||
RealSense2Grabber ( const std::string& file_name_or_serial_number = "", const bool repeat_playback = true ); | ||
|
||
/** \brief virtual Destructor inherited from the Grabber interface. It never throws. */ | ||
virtual ~RealSense2Grabber () noexcept; | ||
|
||
/** \brief Set the device options | ||
* \param[in] width resolution | ||
* \param[in] height resolution | ||
* \param[in] fps target frames per second for the device | ||
*/ | ||
inline void | ||
setDeviceOptions ( uint32_t width, uint32_t height, uint32_t fps = 30 ) | ||
{ | ||
device_width_ = width; | ||
device_height_ = height; | ||
target_fps_ = fps; | ||
|
||
reInitialize (); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a consultation about the specification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this should be handled. Do you want to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated setDeviceOptions so it would restart if it was currently running. |
||
|
||
/** \brief Start the data acquisition. */ | ||
void | ||
start () override; | ||
|
||
/** \brief Stop the data acquisition. */ | ||
void | ||
stop () override; | ||
|
||
/** \brief Check if the data acquisition is still running. */ | ||
bool | ||
isRunning () const override; | ||
|
||
/** \brief Obtain the number of frames per second (FPS). */ | ||
float | ||
getFramesPerSecond () const override; | ||
|
||
/** \brief defined grabber name*/ | ||
std::string | ||
getName () const override { return std::string ( "RealSense2Grabber" ); } | ||
|
||
//define callback signature typedefs | ||
typedef void (signal_librealsense_PointXYZ) ( const pcl::PointCloud<pcl::PointXYZ>::ConstPtr& ); | ||
typedef void (signal_librealsense_PointXYZI) ( const pcl::PointCloud<pcl::PointXYZI>::ConstPtr& ); | ||
typedef void (signal_librealsense_PointXYZRGB) ( const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& ); | ||
typedef void (signal_librealsense_PointXYZRGBA) ( const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& ); | ||
|
||
protected: | ||
|
||
boost::signals2::signal<signal_librealsense_PointXYZ>* signal_PointXYZ; | ||
boost::signals2::signal<signal_librealsense_PointXYZI>* signal_PointXYZI; | ||
boost::signals2::signal<signal_librealsense_PointXYZRGB>* signal_PointXYZRGB; | ||
boost::signals2::signal<signal_librealsense_PointXYZRGBA>* signal_PointXYZRGBA; | ||
|
||
/** \brief Handle when a signal callback has been changed | ||
*/ | ||
void | ||
signalsChanged () override; | ||
|
||
/** \brief the thread function | ||
*/ | ||
void | ||
threadFunction (); | ||
|
||
/** \brief Dynamic reinitialization. | ||
*/ | ||
void | ||
reInitialize (); | ||
|
||
/** \brief Convert a Depth image to a pcl::PointCloud<pcl::PointXYZ> | ||
* \param[in] points the depth points | ||
*/ | ||
pcl::PointCloud<pcl::PointXYZ>::Ptr | ||
convertDepthToPointXYZ ( const rs2::points& points ); | ||
|
||
/** \brief Convert an Infrared Depth image to a pcl::PointCloud<pcl::PointXYZI> | ||
* \param[in] points the depth points | ||
* \param[in] ir Infrared video frame | ||
*/ | ||
pcl::PointCloud<pcl::PointXYZI>::Ptr | ||
convertIntensityDepthToPointXYZRGBI ( const rs2::points& points, const rs2::video_frame& ir ); | ||
|
||
/** \brief Convert an rgb Depth image to a pcl::PointCloud<pcl::PointXYZRGB> | ||
* \param[in] points the depth points | ||
* \param[in] rgb rgb video frame | ||
*/ | ||
pcl::PointCloud<pcl::PointXYZRGB>::Ptr | ||
convertRGBDepthToPointXYZRGB ( const rs2::points& points, const rs2::video_frame& rgb ); | ||
|
||
/** \brief Convert an rgb Depth image to a pcl::PointCloud<pcl::PointXYZRGBA> | ||
* \param[in] points the depth points | ||
* \param[in] rgb rgb video frame | ||
*/ | ||
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr | ||
convertRGBADepthToPointXYZRGBA ( const rs2::points& points, const rs2::video_frame& rgb ); | ||
|
||
/** \brief template function to convert realsense point cloud to PCL point cloud | ||
* \param[in] points - realsense point cloud array | ||
* \param[in] dynamic function to convert individual point color or intensity values | ||
*/ | ||
template <typename PointT, typename Functor> | ||
typename pcl::PointCloud<PointT>::Ptr | ||
convertRealsensePointsToPointCloud ( const rs2::points& points, Functor mapColorFunc ); | ||
|
||
/** \brief Retrieve pixel index for UV texture coordinate | ||
* \param[in] texture the texture | ||
* \param[in] u 2D coordinate | ||
* \param[in] v 2D coordinate | ||
*/ | ||
static size_t | ||
getTextureIdx (const rs2::video_frame & texture, float u, float v); | ||
|
||
/** \brief Retrieve RGB color from texture video frame | ||
* \param[in] texture the texture | ||
* \param[in] u 2D coordinate | ||
* \param[in] v 2D coordinate | ||
*/ | ||
static pcl::RGB | ||
getTextureColor ( const rs2::video_frame& texture, float u, float v ); | ||
SergioRAgostinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** \brief Retrieve color intensity from texture video frame | ||
* \param[in] texture the texture | ||
* \param[in] u 2D coordinate | ||
* \param[in] v 2D coordinate | ||
*/ | ||
static uint8_t | ||
getTextureIntensity ( const rs2::video_frame& texture, float u, float v ); | ||
SergioRAgostinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
/** \brief handle to the thread */ | ||
std::thread thread_; | ||
/** \brief Defines either a file path to a bag file or a realsense device serial number. */ | ||
std::string file_name_or_serial_number_; | ||
/** \brief Repeat playback when reading from file */ | ||
bool repeat_playback_; | ||
/** \brief controlling the state of the thread. */ | ||
bool quit_; | ||
/** \brief Is the grabber running. */ | ||
bool running_; | ||
/** \brief Calculated FPS for the grabber. */ | ||
float fps_; | ||
/** \brief Width for the depth and color sensor. Default 424*/ | ||
uint32_t device_width_; | ||
/** \brief Height for the depth and color sensor. Default 240 */ | ||
uint32_t device_height_; | ||
/** \brief Target FPS for the device. Default 30. */ | ||
SergioRAgostinho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
uint32_t target_fps_; | ||
/** \brief Declare pointcloud object, for calculating pointclouds and texture mappings */ | ||
rs2::pointcloud pc_; | ||
/** \brief Declare RealSense pipeline, encapsulating the actual device and sensors */ | ||
rs2::pipeline pipe_; | ||
}; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UnaNancyOwen -- I feel like lines 216-221 are no longer necessary for the all-in-one installer, but can you please verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary yet.
In case of PCL All-in-one Installer,
realsense2_DIR
needs to refer toPCL_ROOT/3rdParty/librealsense2
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved to librealsense2 in both places