AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
RealSenseD435Manager.cpp
Go to the documentation of this file.
1//
2// RealSenseD435Manager.cpp
3// AI Watch A1
4//
5// Created by Denny Caruso on 23/07/22.
6//
7
8// License: Apache 2.0. See LICENSE file in root directory.
9// Copyright(c) 2022. All Rights Reserved.
10
11#include "RealSenseManager.hpp"
12
13
14
15void RealSenseD435Manager::startEnvironment (rs2::pipeline & pipelineStream, struct rs2_intrinsics & color_intrin, float * scale, unsigned short int resX, unsigned short int resY, bool firstBoot) try {
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}
42
43void RealSenseD435Manager::getVideoFramesRS (unsigned int user_nFrame, rs2::pipeline & pipelineStream, rs2::depth_frame & depthFrame, rs2::frame & colorFrame, rs2::frame & colorizedDepthFrame, const unsigned short int framesToSkip) try {
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 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 ...
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....
void setFrameID(unsigned int frameID)
Set the Frame ID value.
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.
unsigned int getFrameID(void)
Get the current frame ID value.
struct rs2_intrinsics color_intrin
Reference to color stream intrinsics.
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