AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
|
Skeleton class is used for skeleton creations and manipulations. More...
#include <Skeleton.hpp>
Public Member Functions | |
Skeleton (cv::Mat &rgbImage, cv::Mat &distanceImage, cv::Mat &skeletonImage, Json::Value skeletonData) | |
Construct a new Skeleton object. More... | |
~Skeleton (void) | |
Destroy the Skeleton object. More... | |
void | generateSkeleton (void) |
A high-level method that abstracts all the internal structure and operations of the Skeleton class. It first calls calcBodyKeypoints(), then calcBodyEdges(), deprojectSkeletonPoints3D(), convert the coordinates in a specific format and then write them on the RGB image with writeCoordinates(). More... | |
std::vector< bool > | getBodyKeyPointsMap (void) |
Get the BodyKeyPoints Map vector. More... | |
std::vector< Point3D * > | getSkeletonPoints3D_RS (void) |
Get the SkeletonPoints3D RS vector. More... | |
std::vector< Point3D * > * | getSkeletonPoints3D (void) |
Get the Skeleton Points3D vector's pointer. More... | |
float | getConsistency (void) |
Get the Consistency float value. More... | |
Private Member Functions | |
void | setRGB_Image (cv::Mat &rgbImage) |
Set the RGB Image object. More... | |
void | setDistance_Image (cv::Mat &distanceImage) |
Set the Distance Image object. More... | |
void | setSkeleton_Image (cv::Mat &skeleton_Image) |
Set the Skeleton-only Image object. More... | |
void | setBodyKeyPoints (std::vector< BodyKeyPoint > &bodyKeyPoints) |
Set the Body Key Points vector. More... | |
void | setBodyKeyPointsMap (std::vector< bool > &bodyKeyPointsMap) |
Set the Body Key Points Map vector. More... | |
void | setSkeletonData (Json::Value skeletonData) |
Set the Skeleton Data JSON object. More... | |
void | setSkeletonPoints3D_RS (std::vector< Point3D * > skeletonPoints3D_RS) |
Set the SkeletonPoints3D RS vector. More... | |
void | setSkeletonPoints3D (std::vector< Point3D * > *skeletonPoints3D) |
Set the Skeleton Points3D pointer to vector. More... | |
void | setConsistency (float consistency) |
Set the Consistency float value. More... | |
cv::Mat | getRGB_Image (void) |
Get the RGB Image object. More... | |
cv::Mat | getDistance_Image (void) |
Get the Distance Image object. More... | |
cv::Mat | getSkeleton_Image (void) |
Get the Skeleton-only Image object. More... | |
std::vector< BodyKeyPoint > | getBodyKeyPoints (void) |
Get the Body Key Points vector. More... | |
Json::Value | getSkeletonData (void) |
Get the Skeleton Data JSON object. More... | |
void | calcBodyKeypoints (void) |
Retrieve BodyKeyPoints vector and the BodyKeyPoints Map bool vector from OpenPose output, while calculating corresponding Skeleton consistency. More... | |
void | calcBodyEdges (void) |
Calculate Skeleton and invoke methods to draw it on the image according to OpenPose skeleton structure. More... | |
void | drawLine (unsigned char start, unsigned char end) |
Draw a line that starts from a point and ends at another point. The points are specified as unsigned char, since is possible to access the instance BodyKeyPoints vector and get the point. More... | |
void | drawCircle (cv::Point center) |
Draw a circle at the specified point as a parameter. More... | |
void | deprojectSkeletonPoints3D (void) |
Deprojection operation takes a 2D pixel location on a stream's images, as well as a depth, specified in meters, and maps it to a 3D point location within the stream's associated 3D coordinate space. It is provided by the header-only function rs2_deproject_pixel_to_point(...). Intrinsic parameters can be retrieved from any rs2::video_stream_profile object via a call to get_intrinsics(). More... | |
void | writeCoordinates (void) |
Write specific joint points' coordinates on the RGB image. More... | |
Private Attributes | |
cv::Mat | rgb_Image |
RGB frame related to the frame in which the skeleton may appears. More... | |
cv::Mat | distance_Image |
Distance frame related to the frame in which the skeleton may appears. More... | |
cv::Mat | skeleton_Image |
A frame that contains only skeleton information such as green legs and red dots, representing connections between body joints. More... | |
std::vector< BodyKeyPoint > | bodyKeyPoints |
A vector that contains each body joint retrieved from OpenPose. More... | |
std::vector< bool > | bodyKeyPointsMap |
A vector that contains for each body joint retrieved from OpenPose a corresponding boolean that means if that body joint is a valuable and effective body joint or not. A body joint is a BodyKeyPoint with 3 conditions: "x" coordinate is different from zero, "y" coordinate is different from zero, and "confidence" is greater than 0.0. More... | |
Json::Value | skeletonData |
Represents a Skeleton JSON value. This class is a discriminated union wrapper that can represent a: More... | |
std::vector< Point3D * > | skeletonPoints3D_RS |
A vector that contains a set of pointers to Point3D. These points have coordinates whose domain is defined by RealSense Camera and project/deproject operations. More... | |
std::vector< Point3D * > * | skeletonPoints3D |
A pointer to a vector that contains a set of pointers to Point3D. These points have coordinates in which the domain is defined from boundaries parameters specified in "CoordinateMappingManager.hpp". More... | |
float | consistency |
Consistency is a value that represents how accurate is the OpenPose detection for this skeleton. As consequence, a really low consistency value indicates a skeleton that could not there be in the real scene (OpenPose misdetection). Otherwise, a low consistency value indicates a partial skeleton. This value is within the range [0; 1]. More... | |
Skeleton class is used for skeleton creations and manipulations.
Skeleton class is a class that keeps track of the different frames where a specific skeleton may appears, its body key points, correspondent 3D space points, and other useful information skeleton-related.
Definition at line 37 of file Skeleton.hpp.
Skeleton::Skeleton | ( | cv::Mat & | rgbImage, |
cv::Mat & | distanceImage, | ||
cv::Mat & | skeletonImage, | ||
Json::Value | skeletonData | ||
) |
Construct a new Skeleton object.
rgbImage | RGB frame. |
distanceImage | Distance frame. |
skeletonImage | Skeleton frame. |
skeletonData | JSON object of a single person detected by OpenPose. |
Definition at line 187 of file Skeleton.cpp.
References setConsistency(), setDistance_Image(), setRGB_Image(), setSkeleton_Image(), setSkeletonData(), skeleton_Image, and skeletonData.
Skeleton::~Skeleton | ( | void | ) |
Destroy the Skeleton object.
Definition at line 195 of file Skeleton.cpp.
References getSkeletonPoints3D(), and getSkeletonPoints3D_RS().
|
private |
Calculate Skeleton and invoke methods to draw it on the image according to OpenPose skeleton structure.
Definition at line 99 of file Skeleton.cpp.
References drawCircle(), drawLine(), getBodyKeyPoints(), getBodyKeyPointsMap(), LAnkle, LBigToe, LEar, LElbow, LEye, LHeel, LHip, LKnee, LShoulder, MidHip, Neck, Nose, openPoseBodyKeyPointsNumber, RAnkle, RBigToe, REar, RElbow, REye, RHeel, and RKnee.
Referenced by generateSkeleton().
|
private |
Retrieve BodyKeyPoints vector and the BodyKeyPoints Map bool vector from OpenPose output, while calculating corresponding Skeleton consistency.
Definition at line 78 of file Skeleton.cpp.
References bodyKeyPoints, bodyKeyPointsMap, FACADE_SINGLETON_NULLPTR_ERROR, FACADE_SINGLETON_NULLPTR_SCOPE, getConsistency(), FacadeSingleton::getInstance(), FacadeSingleton::getOutputManager(), getSkeletonData(), OutputManagerJSON::getValueAt(), openPoseBodyKeyPointsNumber, setConsistency(), and skeletonData.
Referenced by generateSkeleton().
|
private |
Deprojection operation takes a 2D pixel location on a stream's images, as well as a depth, specified in meters, and maps it to a 3D point location within the stream's associated 3D coordinate space. It is provided by the header-only function rs2_deproject_pixel_to_point(...). Intrinsic parameters can be retrieved from any rs2::video_stream_profile object via a call to get_intrinsics().
Definition at line 145 of file Skeleton.cpp.
References FACADE_SINGLETON_NULLPTR_ERROR, FACADE_SINGLETON_NULLPTR_SCOPE, RealSenseManager::get_color_intrin(), getBodyKeyPoints(), getBodyKeyPointsMap(), FacadeSingleton::getCameraManager(), getDistance_Image(), FacadeSingleton::getInstance(), NEW_ALLOC_ERROR, NEW_ALLOC_SCOPE, and skeletonPoints3D_RS.
Referenced by generateSkeleton().
|
private |
Draw a circle at the specified point as a parameter.
center | points where OpenCV will draw the circle. |
Definition at line 140 of file Skeleton.cpp.
References getRGB_Image(), and getSkeleton_Image().
Referenced by calcBodyEdges().
|
private |
Draw a line that starts from a point and ends at another point. The points are specified as unsigned char, since is possible to access the instance BodyKeyPoints vector and get the point.
start | start point index in the BodyKeyPoints vector. |
end | end point index in the BodyKeyPoints vector. |
Definition at line 131 of file Skeleton.cpp.
References getBodyKeyPoints(), getBodyKeyPointsMap(), getRGB_Image(), and getSkeleton_Image().
Referenced by calcBodyEdges().
void Skeleton::generateSkeleton | ( | void | ) |
A high-level method that abstracts all the internal structure and operations of the Skeleton class. It first calls calcBodyKeypoints(), then calcBodyEdges(), deprojectSkeletonPoints3D(), convert the coordinates in a specific format and then write them on the RGB image with writeCoordinates().
Definition at line 203 of file Skeleton.cpp.
References calcBodyEdges(), calcBodyKeypoints(), deprojectSkeletonPoints3D(), FACADE_SINGLETON_NULLPTR_ERROR, FACADE_SINGLETON_NULLPTR_SCOPE, getBodyKeyPointsMap(), FacadeSingleton::getCoordinateMappingManager(), FacadeSingleton::getInstance(), getSkeletonPoints3D_RS(), CoordinateMappingManager::mapToMeters(), setSkeletonPoints3D(), writeCoordinates(), xOriginUnity, and zOriginUnity.
Referenced by OutputManagerJSON::createJSON().
|
private |
Get the Body Key Points vector.
Definition at line 65 of file Skeleton.cpp.
References bodyKeyPoints.
Referenced by calcBodyEdges(), deprojectSkeletonPoints3D(), drawLine(), and writeCoordinates().
std::vector< bool > Skeleton::getBodyKeyPointsMap | ( | void | ) |
Get the BodyKeyPoints Map vector.
Definition at line 69 of file Skeleton.cpp.
References bodyKeyPointsMap.
Referenced by calcBodyEdges(), OutputManagerJSON::createJSON(), deprojectSkeletonPoints3D(), drawLine(), and generateSkeleton().
float Skeleton::getConsistency | ( | void | ) |
Get the Consistency float value.
Definition at line 222 of file Skeleton.cpp.
References consistency.
Referenced by calcBodyKeypoints(), and OutputManagerJSON::createJSON().
|
private |
Get the Distance Image object.
Definition at line 57 of file Skeleton.cpp.
References distance_Image.
Referenced by deprojectSkeletonPoints3D().
|
private |
Get the RGB Image object.
Definition at line 53 of file Skeleton.cpp.
References rgb_Image.
Referenced by drawCircle(), drawLine(), and writeCoordinates().
|
private |
Get the Skeleton-only Image object.
Definition at line 61 of file Skeleton.cpp.
References skeleton_Image.
Referenced by drawCircle(), and drawLine().
|
private |
Get the Skeleton Data JSON object.
Definition at line 73 of file Skeleton.cpp.
References skeletonData.
Referenced by calcBodyKeypoints().
std::vector< Point3D * > * Skeleton::getSkeletonPoints3D | ( | void | ) |
Get the Skeleton Points3D vector's pointer.
Definition at line 218 of file Skeleton.cpp.
References skeletonPoints3D.
Referenced by OutputManagerJSON::createJSON(), writeCoordinates(), and ~Skeleton().
std::vector< Point3D * > Skeleton::getSkeletonPoints3D_RS | ( | void | ) |
Get the SkeletonPoints3D RS vector.
Definition at line 214 of file Skeleton.cpp.
References skeletonPoints3D_RS.
Referenced by generateSkeleton(), and ~Skeleton().
|
private |
Set the Body Key Points vector.
bodyKeyPoints |
Definition at line 27 of file Skeleton.cpp.
References bodyKeyPoints.
|
private |
Set the Body Key Points Map vector.
bodyKeyPointsMap |
Definition at line 31 of file Skeleton.cpp.
References bodyKeyPointsMap.
|
private |
Set the Consistency float value.
consistency |
Definition at line 47 of file Skeleton.cpp.
References consistency.
Referenced by calcBodyKeypoints(), and Skeleton().
|
private |
Set the Distance Image object.
distanceImage |
Definition at line 19 of file Skeleton.cpp.
References distance_Image.
Referenced by Skeleton().
|
private |
Set the RGB Image object.
rgbImage |
Definition at line 15 of file Skeleton.cpp.
References rgb_Image.
Referenced by Skeleton().
|
private |
Set the Skeleton-only Image object.
skeleton_Image |
Definition at line 23 of file Skeleton.cpp.
References skeleton_Image.
Referenced by Skeleton().
|
private |
Set the Skeleton Data JSON object.
skeletonData |
Definition at line 35 of file Skeleton.cpp.
References skeletonData.
Referenced by Skeleton().
|
private |
Set the Skeleton Points3D pointer to vector.
skeletonPoints3D |
Definition at line 43 of file Skeleton.cpp.
References skeletonPoints3D.
Referenced by generateSkeleton().
|
private |
Set the SkeletonPoints3D RS vector.
skeletonPoints3D_RS |
Definition at line 39 of file Skeleton.cpp.
References skeletonPoints3D_RS.
|
private |
Write specific joint points' coordinates on the RGB image.
Definition at line 169 of file Skeleton.cpp.
References getBodyKeyPoints(), getRGB_Image(), and getSkeletonPoints3D().
Referenced by generateSkeleton().
|
private |
A vector that contains each body joint retrieved from OpenPose.
Definition at line 55 of file Skeleton.hpp.
Referenced by calcBodyKeypoints(), getBodyKeyPoints(), and setBodyKeyPoints().
|
private |
A vector that contains for each body joint retrieved from OpenPose a corresponding boolean that means if that body joint is a valuable and effective body joint or not. A body joint is a BodyKeyPoint with 3 conditions: "x" coordinate is different from zero, "y" coordinate is different from zero, and "confidence" is greater than 0.0.
Definition at line 62 of file Skeleton.hpp.
Referenced by calcBodyKeypoints(), getBodyKeyPointsMap(), and setBodyKeyPointsMap().
|
private |
Consistency is a value that represents how accurate is the OpenPose detection for this skeleton. As consequence, a really low consistency value indicates a skeleton that could not there be in the real scene (OpenPose misdetection). Otherwise, a low consistency value indicates a partial skeleton. This value is within the range [0; 1].
Definition at line 99 of file Skeleton.hpp.
Referenced by getConsistency(), and setConsistency().
|
private |
Distance frame related to the frame in which the skeleton may appears.
Definition at line 46 of file Skeleton.hpp.
Referenced by getDistance_Image(), and setDistance_Image().
|
private |
RGB frame related to the frame in which the skeleton may appears.
Definition at line 42 of file Skeleton.hpp.
Referenced by getRGB_Image(), and setRGB_Image().
|
private |
A frame that contains only skeleton information such as green legs and red dots, representing connections between body joints.
Definition at line 50 of file Skeleton.hpp.
Referenced by getSkeleton_Image(), setSkeleton_Image(), and Skeleton().
|
private |
Represents a Skeleton JSON value. This class is a discriminated union wrapper that can represent a:
In this case this JSON Value contains all informations about body joints retrieved from OpenPose JSON output.
Definition at line 78 of file Skeleton.hpp.
Referenced by calcBodyKeypoints(), getSkeletonData(), setSkeletonData(), and Skeleton().
|
private |
A pointer to a vector that contains a set of pointers to Point3D. These points have coordinates in which the domain is defined from boundaries parameters specified in "CoordinateMappingManager.hpp".
Definition at line 93 of file Skeleton.hpp.
Referenced by getSkeletonPoints3D(), and setSkeletonPoints3D().
|
private |
A vector that contains a set of pointers to Point3D. These points have coordinates whose domain is defined by RealSense Camera and project/deproject operations.
Definition at line 85 of file Skeleton.hpp.
Referenced by deprojectSkeletonPoints3D(), getSkeletonPoints3D_RS(), and setSkeletonPoints3D_RS().