AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
RealSenseD435Manager Class Reference

RealSenseD435Manager class is a class that abstracts the behavior of an Intel RealSense D435 Camera, in order to capture frames, apply post-processing, and so on. More...

#include <RealSenseManager.hpp>

Inheritance diagram for RealSenseD435Manager:
RealSenseManager

Public Member Functions

void startEnvironment (rs2::pipeline &pipelineStream, struct rs2_intrinsics &color_intrin, float *scale, unsigned short int resX, unsigned short int resY, bool firstBoot) override
 This method is useful to invoke at the boot of the program where we want to initialize the different mangers, start the camera and set up the related environment. This method is specific for D435 Intel RealSense camera. More...
 
void getVideoFramesRS (unsigned int user_nFrame, rs2::pipeline &pipelineStream, rs2::depth_frame &depthFrame, rs2::frame &colorFrame, rs2::frame &colorizedDepthFrame, const unsigned short int framesToSkip) override
 Get user_nFrame video frames from the pipeline by applying a specific scaling factor. This method is specific for D435 Intel RealSense camera. More...
 
unsigned int getFrameID (void)
 Get the current frame ID value. More...
 
struct rs2_intrinsics & get_color_intrin (void)
 Get the color intrinsics object. More...
 

Protected Member Functions

void setFrameID (unsigned int frameID)
 Set the Frame ID value. More...
 
void set_align (rs2::align align)
 Set the align object. More...
 
void set_depth_intrin (struct rs2_intrinsics depth_intrin)
 Set the depth intrinsics object. More...
 
void set_color_intrin (struct rs2_intrinsics &color_intrin)
 Set the color intrinsics object. More...
 
void set_depth_to_color (struct rs2_extrinsics depth_to_color)
 Set the depth extrinsics object. More...
 
void set_color_to_depth (struct rs2_extrinsics color_to_depth)
 Set the color extrinsics object. More...
 
rs2::align get_align (void)
 Get the align object. More...
 
struct rs2_intrinsics get_depth_intrin (void)
 Get the depth intrinsics object. More...
 
struct rs2_extrinsics get_depth_to_color (void)
 Get the depth extrinsics object. More...
 
struct rs2_extrinsics get_color_to_depth (void)
 Get the color extrinsics object. More...
 

Private Attributes

unsigned int frameID
 Current frame counter. More...
 
rs2::align align
 Auxiliary processing block that performs image alignment using depth data and camera calibration. More...
 
struct rs2_intrinsics depth_intrin
 Reference to depth stream intrinsics. More...
 
struct rs2_intrinsics color_intrin
 Reference to color stream intrinsics. More...
 
struct rs2_extrinsics depth_to_color
 Reference to depth stream extrinsics. More...
 
struct rs2_extrinsics color_to_depth
 Reference to color stream extrinsics. More...
 

Detailed Description

RealSenseD435Manager class is a class that abstracts the behavior of an Intel RealSense D435 Camera, in order to capture frames, apply post-processing, and so on.

Definition at line 178 of file RealSenseManager.hpp.

Member Function Documentation

◆ get_align()

rs2::align RealSenseManager::get_align ( void  )
protectedinherited

Get the align object.

Returns
rs2::align
See also
http://docs.ros.org/en/kinetic/api/librealsense2/html/classrs2_1_1align.html

Definition at line 39 of file RealSenseManager.cpp.

39 {
40 return this->align;
41}
rs2::align align
Auxiliary processing block that performs image alignment using depth data and camera calibration.

References RealSenseManager::align.

Referenced by getVideoFramesRS().

◆ get_color_intrin()

struct rs2_intrinsics & RealSenseManager::get_color_intrin ( void  )
inherited

Get the color intrinsics object.

Returns
struct rs2_intrinsics &

Definition at line 65 of file RealSenseManager.cpp.

65 {
66 return this->color_intrin;
67}
struct rs2_intrinsics color_intrin
Reference to color stream intrinsics.

References RealSenseManager::color_intrin.

Referenced by Skeleton::deprojectSkeletonPoints3D().

◆ get_color_to_depth()

struct rs2_extrinsics RealSenseManager::get_color_to_depth ( void  )
protectedinherited

Get the color extrinsics object.

Returns
struct rs2_extrinsics

Definition at line 51 of file RealSenseManager.cpp.

51 {
52 return this->color_to_depth;
53}
struct rs2_extrinsics color_to_depth
Reference to color stream extrinsics.

◆ get_depth_intrin()

struct rs2_intrinsics RealSenseManager::get_depth_intrin ( void  )
protectedinherited

Get the depth intrinsics object.

Returns
struct rs2_intrinsics

Definition at line 43 of file RealSenseManager.cpp.

43 {
44 return this->depth_intrin;
45}
struct rs2_intrinsics depth_intrin
Reference to depth stream intrinsics.

◆ get_depth_to_color()

struct rs2_extrinsics RealSenseManager::get_depth_to_color ( void  )
protectedinherited

Get the depth extrinsics object.

Returns
struct rs2_extrinsics

Definition at line 47 of file RealSenseManager.cpp.

47 {
48 return this->depth_to_color;
49}
struct rs2_extrinsics depth_to_color
Reference to depth stream extrinsics.

◆ getFrameID()

unsigned int RealSenseManager::getFrameID ( void  )
inherited

Get the current frame ID value.

Returns
unsigned int

Definition at line 61 of file RealSenseManager.cpp.

61 {
62 return this->frameID;
63}
unsigned int frameID
Current frame counter.

References RealSenseManager::frameID.

Referenced by OpenCV_Manager::getVideoFramesCV(), getVideoFramesRS(), FacadeSingleton::sendData(), and OpenCV_Manager::showSkeletonsCV().

◆ getVideoFramesRS()

void RealSenseD435Manager::getVideoFramesRS ( unsigned int  user_nFrame,
rs2::pipeline &  pipelineStream,
rs2::depth_frame &  depthFrame,
rs2::frame &  colorFrame,
rs2::frame &  colorizedDepthFrame,
const unsigned short int  framesToSkip 
)
overridevirtual

Get user_nFrame video frames from the pipeline by applying a specific scaling factor. This method is specific for D435 Intel RealSense camera.

Parameters
user_nFrameframe's number to capture according to user choice.
pipelineStreamThe pipeline simplifies the user interaction with the device and computer vision processing modules. The class abstracts the camera configuration and streaming, and the vision modules triggering and threading. It lets the application focus on the computer vision output of the modules, or the device output data. The pipeline can manage computer vision modules, which are implemented as a processing block. The pipeline is the consumer of the processing block interface, while the application consumes the computer vision interface.
depthFrameReference to depth frame object that will be captured.
colorFrameReference to color frame object that will be captured.
colorizedDepthFrameReference to colorized depth frame object that will be captured.
framesToSkipFrames' number to skip in order to ignore a certain amount of frames and extend the recording interval. A '0' value means 'capture each frame'.
See also
https://dev.intelrealsense.com/docs/docs-get-started
getVideoFramesCV(unsigned int user_nFrame, rs2::pipeline & pipelineStream, float scale)
getVideoFrames (unsigned int user_nFrame, rs2::pipeline & pipelineStream, float scale)

Implements RealSenseManager.

Definition at line 43 of file RealSenseD435Manager.cpp.

43 {
44 rs2::colorizer colorMap;
45 rs2::spatial_filter spatialFilter;
46 rs2::frameset streamData, alignedStreamData;
47 unsigned short int skippedFrameCounter = 0;
48
49 // Capture frames and apply post-processing
50 do {
51 streamData = pipelineStream.wait_for_frames();
52 skippedFrameCounter += 1;
53 } while (skippedFrameCounter <= framesToSkip);
54
55 alignedStreamData = RealSenseManager::get_align().process(streamData);
56 depthFrame = alignedStreamData.get_depth_frame();
57 spatialFilter.set_option(RS2_OPTION_HOLES_FILL, 1);
58 depthFrame = spatialFilter.process(depthFrame);
59
60 colorFrame = alignedStreamData.get_color_frame();
61 colorizedDepthFrame = depthFrame.apply_filter(colorMap);
63} catch (const rs2::error & e){
64 std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
66} catch (const std::exception & e) {
67 std::cerr << e.what() << std::endl;
69}
void setFrameID(unsigned int frameID)
Set the Frame ID value.
unsigned int getFrameID(void)
Get the current frame ID value.
rs2::align get_align(void)
Get the align object.
static const char * RS_CAMERA_SCOPE
Definition: constants.hpp:30
static const short int RS_CAMERA_ERROR
Definition: constants.hpp:29

References RealSenseManager::get_align(), RealSenseManager::getFrameID(), and RealSenseManager::setFrameID().

◆ set_align()

void RealSenseManager::set_align ( rs2::align  align)
protectedinherited

Set the align object.

See also
http://docs.ros.org/en/kinetic/api/librealsense2/html/classrs2_1_1align.html
Parameters
alignAuxiliary processing block that performs image alignment using depth data and camera calibration.

Definition at line 19 of file RealSenseManager.cpp.

19 {
20 this->align = align;
21}

References RealSenseManager::align.

Referenced by startEnvironment().

◆ set_color_intrin()

void RealSenseManager::set_color_intrin ( struct rs2_intrinsics &  color_intrin)
protectedinherited

Set the color intrinsics object.

Parameters
color_intrinReference to color stream intrinsics.

Definition at line 27 of file RealSenseManager.cpp.

27 {
29}

References RealSenseManager::color_intrin.

Referenced by startEnvironment().

◆ set_color_to_depth()

void RealSenseManager::set_color_to_depth ( struct rs2_extrinsics  color_to_depth)
protectedinherited

Set the color extrinsics object.

Parameters
color_to_depthReference to color stream extrinsics.

Definition at line 35 of file RealSenseManager.cpp.

35 {
37}

References RealSenseManager::color_to_depth.

Referenced by startEnvironment().

◆ set_depth_intrin()

void RealSenseManager::set_depth_intrin ( struct rs2_intrinsics  depth_intrin)
protectedinherited

Set the depth intrinsics object.

Parameters
depth_intrinReference to depth stream intrinsics.

Definition at line 23 of file RealSenseManager.cpp.

23 {
25}

References RealSenseManager::depth_intrin.

Referenced by startEnvironment().

◆ set_depth_to_color()

void RealSenseManager::set_depth_to_color ( struct rs2_extrinsics  depth_to_color)
protectedinherited

Set the depth extrinsics object.

Parameters
depth_to_colorReference to depth stream extrinsics.

Definition at line 31 of file RealSenseManager.cpp.

31 {
33}

References RealSenseManager::depth_to_color.

Referenced by startEnvironment().

◆ setFrameID()

void RealSenseManager::setFrameID ( unsigned int  frameID)
protectedinherited

Set the Frame ID value.

Parameters
frameIDCurrent frame counter.

Definition at line 15 of file RealSenseManager.cpp.

15 {
16 this->frameID = frameID;
17}

References RealSenseManager::frameID.

Referenced by getVideoFramesRS(), and RealSenseManager::RealSenseManager().

◆ startEnvironment()

void RealSenseD435Manager::startEnvironment ( rs2::pipeline &  pipelineStream,
struct rs2_intrinsics &  color_intrin,
float *  scale,
unsigned short int  resX,
unsigned short int  resY,
bool  firstBoot 
)
overridevirtual

This method is useful to invoke at the boot of the program where we want to initialize the different mangers, start the camera and set up the related environment. This method is specific for D435 Intel RealSense camera.

Parameters
pipelineStreamThe pipeline simplifies the user interaction with the device and computer vision processing modules. The class abstracts the camera configuration and streaming, and the vision modules triggering and threading. It lets the application focus on the computer vision output of the modules, or the device output data. The pipeline can manage computer vision modules, which are implemented as a processing block. The pipeline is the consumer of the processing block interface, while the application consumes the computer vision interface.
color_intrinReference to color video stream intrinsics.
scalePointer to scaling factor.
resXx resoultion <->.
resYy resolution.
firstBoottrue if the method is called for the first time (in this case a kind of camera calibration is done), false otherwise.
See also
https://dev.intelrealsense.com/docs/docs-get-started
startEnvironment(rs2::pipeline & pipelineStream, struct rs2_intrinsics & color_intrin, float * scale, unsigned short int resX, unsigned short int resY, const char * destinationKafkaTopic)

Implements RealSenseManager.

Definition at line 15 of file RealSenseD435Manager.cpp.

15 {
16 rs2::log_to_console(RS2_LOG_SEVERITY_ERROR);
17 rs2::rates_printer printer;
18 rs2::config myConfiguration;
19 myConfiguration.enable_stream(rs2_stream::RS2_STREAM_DEPTH, resX, resY, rs2_format::RS2_FORMAT_Z16);
20 myConfiguration.enable_stream(rs2_stream::RS2_STREAM_COLOR, resX, resY, rs2_format::RS2_FORMAT_RGB8);
21 rs2::pipeline_profile myPipelineProfile = pipelineStream.start(myConfiguration);
22 rs2::align align_to(RS2_STREAM_COLOR);
23 RealSenseManager::set_align(rs2::align(align_to));
24 rs2::depth_sensor sensor = myPipelineProfile.get_device().first<rs2::depth_sensor>();
25 * scale = sensor.get_depth_scale();
26
27 // Capture 30 frames to give autoexposure, etc. a chance to settle
28 if (firstBoot) for (int i = 0; i < 30; i++) pipelineStream.wait_for_frames();
29
30 RealSenseManager::set_depth_intrin(myPipelineProfile.get_stream(RS2_STREAM_DEPTH).as<rs2::video_stream_profile>().get_intrinsics());
31 color_intrin = myPipelineProfile.get_stream(RS2_STREAM_COLOR).as<rs2::video_stream_profile>().get_intrinsics();
33 RealSenseManager::set_color_to_depth(myPipelineProfile.get_stream(RS2_STREAM_DEPTH).as<rs2::video_stream_profile>().get_extrinsics_to(myPipelineProfile.get_stream(RS2_STREAM_COLOR)));
34 RealSenseManager::set_depth_to_color(myPipelineProfile.get_stream(RS2_STREAM_COLOR).as<rs2::video_stream_profile>().get_extrinsics_to(myPipelineProfile.get_stream(RS2_STREAM_DEPTH)));
35} catch (const rs2::error & e){
36 std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
38} catch (const std::exception & e) {
39 std::cerr << e.what() << std::endl;
41}
void set_depth_to_color(struct rs2_extrinsics depth_to_color)
Set the depth extrinsics object.
void set_color_intrin(struct rs2_intrinsics &color_intrin)
Set the color intrinsics object.
void set_depth_intrin(struct rs2_intrinsics depth_intrin)
Set the depth intrinsics object.
void set_align(rs2::align align)
Set the align object.
void set_color_to_depth(struct rs2_extrinsics color_to_depth)
Set the color extrinsics object.

References RealSenseManager::color_intrin, RealSenseManager::set_align(), RealSenseManager::set_color_intrin(), RealSenseManager::set_color_to_depth(), RealSenseManager::set_depth_intrin(), and RealSenseManager::set_depth_to_color().

Member Data Documentation

◆ align

rs2::align RealSenseManager::align
privateinherited

Auxiliary processing block that performs image alignment using depth data and camera calibration.

See also
http://docs.ros.org/en/kinetic/api/librealsense2/html/classrs2_1_1align.html

Definition at line 35 of file RealSenseManager.hpp.

Referenced by RealSenseManager::get_align(), and RealSenseManager::set_align().

◆ color_intrin

struct rs2_intrinsics RealSenseManager::color_intrin
privateinherited

◆ color_to_depth

struct rs2_extrinsics RealSenseManager::color_to_depth
privateinherited

Reference to color stream extrinsics.

See also
https://dev.intelrealsense.com/docs/projection-in-intel-realsense-sdk-20

Definition at line 55 of file RealSenseManager.hpp.

Referenced by RealSenseManager::set_color_to_depth().

◆ depth_intrin

struct rs2_intrinsics RealSenseManager::depth_intrin
privateinherited

Reference to depth stream intrinsics.

See also
https://dev.intelrealsense.com/docs/projection-in-intel-realsense-sdk-20

Definition at line 40 of file RealSenseManager.hpp.

Referenced by RealSenseManager::set_depth_intrin().

◆ depth_to_color

struct rs2_extrinsics RealSenseManager::depth_to_color
privateinherited

Reference to depth stream extrinsics.

See also
https://dev.intelrealsense.com/docs/projection-in-intel-realsense-sdk-20

Definition at line 50 of file RealSenseManager.hpp.

Referenced by RealSenseManager::set_depth_to_color().

◆ frameID

unsigned int RealSenseManager::frameID
privateinherited

Current frame counter.

Definition at line 30 of file RealSenseManager.hpp.

Referenced by RealSenseManager::getFrameID(), and RealSenseManager::setFrameID().


The documentation for this class was generated from the following files: