AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
|
FacadeSingleton class is used as a single access point to a simplified interface. More...
#include <FacadeSingleton.hpp>
Public Member Functions | |
FacadeSingleton (FacadeSingleton &other)=delete | |
Disabling the possibility to clone the Singleton object. Singletons should not be cloneable. More... | |
void | operator= (const FacadeSingleton &)=delete |
Disabling the possibility to assign a Singleton object. Singletons should not be assignable. More... | |
RealSenseManager * | getCameraManager (void) |
Get the RealSenseManager pointer. More... | |
OutputManager * | getOutputManager (void) |
Get the OutputManager pointer. More... | |
OpenCV_Manager * | getOpenCV_Manager (void) |
Get the OpenCV_Manager pointer. More... | |
UsageManager * | getUsageManager (void) |
Get the UsageManager pointer. More... | |
CoordinateMappingManager * | getCoordinateMappingManager (void) |
Get the CoordinateMappingManager pointer. More... | |
ImageManager * | getImageManager (void) |
Get the ImageManager pointer. More... | |
KafkaManager * | getKafkaManager (void) |
Get the KafkaManager pointer. More... | |
void | startEnvironment (rs2::pipeline &pipelineStream, struct rs2_intrinsics &color_intrin, float *scale, unsigned short int resX, unsigned short int resY, const char *destinationKafkaTopic, Room room) |
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. More... | |
void | getVideoFrames (unsigned int user_nFrame, rs2::pipeline &pipelineStream, float scale, const unsigned short int framesToSkip) |
Get user_nFrame video frames from the pipeline by applying a specific scaling factor. More... | |
void | getVideoBodyKeyPoints (int *argc, char ***argv) |
Start and execute OpenPose submodule. More... | |
void | showSkeletons (unsigned int user_nFrame, const float skeletonThreshold) |
Retrieve OpenPose's output, convert it to RealSense coordinate's space, show results and save them. More... | |
void | sendData (unsigned int user_nFrame) |
Send saved results by getVideoBodyKeyPoints(...) via Kafka using the KafkaManager. More... | |
void | cleanBuildFolder (void) |
This method cleans the build folder, in order to prepare the environment for the next loop iteration. It does this by deleting all images and JSON files produced during the current loop iteration. More... | |
Static Public Member Functions | |
static FacadeSingleton * | getInstance (const int expected_argc, const char *expectedUsageMessage) |
Get the unique class instance, given input parameters. This method should be called the first time when we want to create a reference to the object of this class. More... | |
static FacadeSingleton * | getInstance (void) |
Get the unique class instance. This methods should be called in the following scenario: when we just want to retrieve the reference to the object of this class. More... | |
Protected Member Functions | |
void | setCameraManager (RealSenseManager *cameraManager) |
Set the RealSenseManager pointer. More... | |
void | setOutputManager (OutputManager *outputManager) |
Set the OutputManager pointer. More... | |
void | setOpenCV_Manager (OpenCV_Manager *openCV_Manager) |
Set the OpenCV_Manager pointer. More... | |
void | setUsageManager (UsageManager *usageManager) |
Set the UsageManager pointer. More... | |
void | setCoordinateMappingManager (CoordinateMappingManager *coordinateMappingManager) |
Set the CoordinateMappingManager pointer. More... | |
void | setImageManager (ImageManager *imageManager) |
Set the ImageManager pointer. More... | |
void | setKafkaManager (KafkaManager *kafkaManager) |
Set the KafkaManager pointer. More... | |
Private Member Functions | |
FacadeSingleton (const int expected_argc=0, const char *expectedUsageMessage=nullptr) | |
Construct a new Facade Singleton object. More... | |
~FacadeSingleton (void) | |
Destroy the Facade Singleton object. More... | |
Private Attributes | |
RealSenseManager * | cameraManager |
A pointer to RealSenseManager object. A RealSenseManager object is responsible for handling the camera setup, frames acquisition and frames post-processing. More... | |
OutputManager * | outputManager |
A pointer to OutputManager object. An OutputManager object is responsible for handling the final output generation to send via Kafka later on. More... | |
OpenCV_Manager * | openCV_Manager |
A pointer to OpenCV_Manager object. An OpenCV_Manager object is responsible for converting camera frame to an OpenCV matrix and booting building skeletons into the image. More... | |
UsageManager * | usageManager |
A pointer to UsageManager object. An UsageManager object is responsible for checking if the parameters read from configuration file are fine, correct and valid. Furthermore this class provides methods to access this parameters. More... | |
CoordinateMappingManager * | coordinateMappingManager |
A pointer to CoordinateMappingManager object. A CoordinateMappingManager object is responsible for transforming one coordinate range values' space into another one. For instance, it can transform a RealSense coordinates space to meters or to Unity coordinates. In both cases, there are several parameters to set up regarding the scene and the room where the camera is installed. More... | |
ImageManager * | imageManager |
A pointer to CoordinateMappingManager object. A CoordinateMappingManager object is responsible for broad tasks such as loading, saving, and showing images, as well as releasing the memory allocated for those images. More... | |
KafkaManager * | kafkaManager |
A pointer to KafkaManager object. A KafkaManager object is responsible for sending previously produced JSON output via Kafka. More... | |
Static Private Attributes | |
static FacadeSingleton * | sharedInstance { nullptr } |
The field for storing the singleton instance. More... | |
static std::mutex | singletonMutex |
Mutex for thread-safe access. More... | |
FacadeSingleton class is used as a single access point to a simplified interface.
A facade is a structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of classes. A Facade class can often be transformed into a Singleton since a single facade object is sufficient in most cases. Since we need just one access point to this class and since the internal submodules are complex, a class FacadeSingleton implements both behaviors.
Definition at line 44 of file FacadeSingleton.hpp.
|
private |
Construct a new Facade Singleton object.
expected_argc | the number of parameters that the program expects to find in the configuration file. |
expectedUsageMessage | a simple message that lets the user understand how to properly run the executable. |
Definition at line 20 of file FacadeSingleton.cpp.
References CONF_FILE_PATH, expected_argc, expectedUsageMessage, UsageManager::getInstance(), NEW_ALLOC_ERROR, NEW_ALLOC_SCOPE, setUsageManager(), and totalFileParameters.
Referenced by getInstance().
|
private |
Destroy the Facade Singleton object.
Definition at line 42 of file FacadeSingleton.cpp.
References getCameraManager(), getCoordinateMappingManager(), getImageManager(), getKafkaManager(), getOpenCV_Manager(), getOutputManager(), getUsageManager(), and sharedInstance.
|
delete |
Disabling the possibility to clone the Singleton object. Singletons should not be cloneable.
other |
void FacadeSingleton::cleanBuildFolder | ( | void | ) |
This method cleans the build folder, in order to prepare the environment for the next loop iteration. It does this by deleting all images and JSON files produced during the current loop iteration.
Definition at line 166 of file FacadeSingleton.cpp.
References SystemCommand::executeCommand(), and getUsageManager().
Referenced by main(), and startEnvironment().
RealSenseManager * FacadeSingleton::getCameraManager | ( | void | ) |
Get the RealSenseManager pointer.
Definition at line 95 of file FacadeSingleton.cpp.
References cameraManager.
Referenced by Skeleton::deprojectSkeletonPoints3D(), OpenCV_Manager::getVideoFramesCV(), sendData(), OpenCV_Manager::showSkeletonsCV(), startEnvironment(), and ~FacadeSingleton().
CoordinateMappingManager * FacadeSingleton::getCoordinateMappingManager | ( | void | ) |
Get the CoordinateMappingManager pointer.
Definition at line 111 of file FacadeSingleton.cpp.
References coordinateMappingManager.
Referenced by Skeleton::generateSkeleton(), and ~FacadeSingleton().
ImageManager * FacadeSingleton::getImageManager | ( | void | ) |
Get the ImageManager pointer.
Definition at line 115 of file FacadeSingleton.cpp.
References imageManager.
Referenced by OpenCV_Manager::getVideoFramesCV(), OpenCV_Manager::showSkeletonsCV(), and ~FacadeSingleton().
|
static |
Get the unique class instance, given input parameters. This method should be called the first time when we want to create a reference to the object of this class.
expected_argc | the number of parameters that the program expects to find in the configuration file. |
expectedUsageMessage | a simple message that lets the user understand how to properly run the |
Definition at line 83 of file FacadeSingleton.cpp.
References expected_argc, expectedUsageMessage, FacadeSingleton(), sharedInstance, and singletonMutex.
|
static |
Get the unique class instance. This methods should be called in the following scenario: when we just want to retrieve the reference to the object of this class.
Definition at line 89 of file FacadeSingleton.cpp.
References sharedInstance, and singletonMutex.
Referenced by Skeleton::calcBodyKeypoints(), Skeleton::deprojectSkeletonPoints3D(), Skeleton::generateSkeleton(), OpenCV_Manager::getVideoFramesCV(), main(), and OpenCV_Manager::showSkeletonsCV().
KafkaManager * FacadeSingleton::getKafkaManager | ( | void | ) |
Get the KafkaManager pointer.
Definition at line 119 of file FacadeSingleton.cpp.
References kafkaManager.
Referenced by sendData(), and ~FacadeSingleton().
OpenCV_Manager * FacadeSingleton::getOpenCV_Manager | ( | void | ) |
Get the OpenCV_Manager pointer.
Definition at line 103 of file FacadeSingleton.cpp.
References openCV_Manager.
Referenced by getVideoFrames(), showSkeletons(), and ~FacadeSingleton().
OutputManager * FacadeSingleton::getOutputManager | ( | void | ) |
Get the OutputManager pointer.
Definition at line 99 of file FacadeSingleton.cpp.
References outputManager.
Referenced by Skeleton::calcBodyKeypoints(), sendData(), OpenCV_Manager::showSkeletonsCV(), and ~FacadeSingleton().
UsageManager * FacadeSingleton::getUsageManager | ( | void | ) |
Get the UsageManager pointer.
Definition at line 107 of file FacadeSingleton.cpp.
References usageManager.
Referenced by cleanBuildFolder(), sendData(), OpenCV_Manager::showSkeletonsCV(), and ~FacadeSingleton().
void FacadeSingleton::getVideoBodyKeyPoints | ( | int * | argc, |
char *** | argv | ||
) |
Start and execute OpenPose submodule.
argc | arguments' number specified on launch (from main). |
argv | arguments' specified on launch (from main). |
Definition at line 139 of file FacadeSingleton.cpp.
References SystemCommand::executeCommand().
Referenced by main().
void FacadeSingleton::getVideoFrames | ( | unsigned int | user_nFrame, |
rs2::pipeline & | pipelineStream, | ||
float | scale, | ||
const unsigned short int | framesToSkip | ||
) |
Get user_nFrame video frames from the pipeline by applying a specific scaling factor.
user_nFrame | frame's number to capture according to user choice. |
pipelineStream | The 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. |
scale | Scaling factor. |
framesToSkip | Frames' number to skip in order to ignore a certain amount of frames and extend the recording interval. A '0' value means 'capture each frame'. |
Definition at line 135 of file FacadeSingleton.cpp.
References getOpenCV_Manager(), and OpenCV_Manager::getVideoFramesCV().
Referenced by main().
|
delete |
Disabling the possibility to assign a Singleton object. Singletons should not be assignable.
void FacadeSingleton::sendData | ( | unsigned int | user_nFrame | ) |
Send saved results by getVideoBodyKeyPoints(...) via Kafka using the KafkaManager.
user_nFrame | frame's number to capture according to user choice. |
Definition at line 149 of file FacadeSingleton.cpp.
References UsageManager::get_argv(), getCameraManager(), RealSenseManager::getFrameID(), getKafkaManager(), getOutputManager(), getUsageManager(), OutputManagerJSON::loadJSON(), outputFolderOffset, and KafkaManager::sendData().
Referenced by main().
|
protected |
Set the RealSenseManager pointer.
cameraManager | pointer to a RealSenseManager object. |
Definition at line 53 of file FacadeSingleton.cpp.
References cameraManager.
Referenced by startEnvironment().
|
protected |
Set the CoordinateMappingManager pointer.
coordinateMappingManager | pointer to an CoordinateMappingManager object. |
Definition at line 69 of file FacadeSingleton.cpp.
References coordinateMappingManager.
Referenced by startEnvironment().
|
protected |
Set the ImageManager pointer.
imageManager | pointer to an ImageManager object. |
Definition at line 73 of file FacadeSingleton.cpp.
References imageManager.
Referenced by startEnvironment().
|
protected |
Set the KafkaManager pointer.
kafkaManager | pointer to a KafkaManager object. |
Definition at line 77 of file FacadeSingleton.cpp.
References kafkaManager.
Referenced by startEnvironment().
|
protected |
Set the OpenCV_Manager pointer.
openCV_Manager | pointer to an OpenCV_Manager object. |
Definition at line 61 of file FacadeSingleton.cpp.
References openCV_Manager.
Referenced by startEnvironment().
|
protected |
Set the OutputManager pointer.
outputManager | pointer to an OutputManager object. |
Definition at line 57 of file FacadeSingleton.cpp.
References outputManager.
Referenced by startEnvironment().
|
protected |
Set the UsageManager pointer.
usageManager | pointer to an UsageManager object. |
Definition at line 65 of file FacadeSingleton.cpp.
References usageManager.
Referenced by FacadeSingleton().
void FacadeSingleton::showSkeletons | ( | unsigned int | user_nFrame, |
const float | skeletonThreshold | ||
) |
Retrieve OpenPose's output, convert it to RealSense coordinate's space, show results and save them.
user_nFrame | frame's number to capture according to user choice. |
skeletonThreshold | The magnitude or intensity that must be exceeded for a specific reaction, phenomenon, result, or condition to occur or be manifested. In this case, if the skeleton's confidence mean value is greater than "skeletonThreshold", then the skeleton will be considered a meaningful skeleton. |
Definition at line 145 of file FacadeSingleton.cpp.
References getOpenCV_Manager(), and OpenCV_Manager::showSkeletonsCV().
Referenced by main().
void FacadeSingleton::startEnvironment | ( | rs2::pipeline & | pipelineStream, |
struct rs2_intrinsics & | color_intrin, | ||
float * | scale, | ||
unsigned short int | resX, | ||
unsigned short int | resY, | ||
const char * | destinationKafkaTopic, | ||
Room | room | ||
) |
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.
pipelineStream | The 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_intrin | Reference to color video stream intrinsics. |
scale | Pointer to scaling factor. |
resX | x resoultion <->. |
resY | y resolution. |
destinationKafkaTopic | the destination's kafka topic's name. |
room | Specific room within which the coordinate mapping will be done. |
Definition at line 123 of file FacadeSingleton.cpp.
References cleanBuildFolder(), FIRST_BOOT, getCameraManager(), setCameraManager(), setCoordinateMappingManager(), setImageManager(), setKafkaManager(), setOpenCV_Manager(), setOutputManager(), and RealSenseManager::startEnvironment().
Referenced by main().
|
private |
A pointer to RealSenseManager object. A RealSenseManager object is responsible for handling the camera setup, frames acquisition and frames post-processing.
Definition at line 62 of file FacadeSingleton.hpp.
Referenced by getCameraManager(), and setCameraManager().
|
private |
A pointer to CoordinateMappingManager object. A CoordinateMappingManager object is responsible for transforming one coordinate range values' space into another one. For instance, it can transform a RealSense coordinates space to meters or to Unity coordinates. In both cases, there are several parameters to set up regarding the scene and the room where the camera is installed.
Definition at line 90 of file FacadeSingleton.hpp.
Referenced by getCoordinateMappingManager(), and setCoordinateMappingManager().
|
private |
A pointer to CoordinateMappingManager object. A CoordinateMappingManager object is responsible for broad tasks such as loading, saving, and showing images, as well as releasing the memory allocated for those images.
Definition at line 97 of file FacadeSingleton.hpp.
Referenced by getImageManager(), and setImageManager().
|
private |
A pointer to KafkaManager object. A KafkaManager object is responsible for sending previously produced JSON output via Kafka.
Definition at line 103 of file FacadeSingleton.hpp.
Referenced by getKafkaManager(), and setKafkaManager().
|
private |
A pointer to OpenCV_Manager object. An OpenCV_Manager object is responsible for converting camera frame to an OpenCV matrix and booting building skeletons into the image.
Definition at line 74 of file FacadeSingleton.hpp.
Referenced by getOpenCV_Manager(), and setOpenCV_Manager().
|
private |
A pointer to OutputManager object. An OutputManager object is responsible for handling the final output generation to send via Kafka later on.
Definition at line 68 of file FacadeSingleton.hpp.
Referenced by getOutputManager(), and setOutputManager().
|
staticprivate |
The field for storing the singleton instance.
Definition at line 49 of file FacadeSingleton.hpp.
Referenced by getInstance(), and ~FacadeSingleton().
|
staticprivate |
Mutex for thread-safe access.
Definition at line 53 of file FacadeSingleton.hpp.
Referenced by getInstance().
|
private |
A pointer to UsageManager object. An UsageManager object is responsible for checking if the parameters read from configuration file are fine, correct and valid. Furthermore this class provides methods to access this parameters.
Definition at line 81 of file FacadeSingleton.hpp.
Referenced by getUsageManager(), and setUsageManager().