21#include <opencv2/core.hpp>
78 cv::FileStorage fs(fname, cv::FileStorage::READ);
79 if (fs.isOpened() ==
false)
LFATAL(
"Cannot read " << fname);
81 cv::FileNode node; cv::FileNodeIterator it;
84 node = fs[
"nodeNames"];
85 if (node.isSeq() ==
false)
LTHROW(
"Required nodeNames array missing or not an array");
86 for (it = node.begin(); it != node.end(); ++it)
87 { cv::FileNode item = *it;
nodeNames.emplace_back((std::string)(item)); }
89 node = fs[
"nodeColors"];
90 if (node.isSeq() ==
false)
LTHROW(
"Required nodeColors array missing or not an array");
91 for (it = node.begin(); it != node.end(); ++it)
92 { cv::FileNode item = *it;
nodeColors.emplace_back(std::stoul((std::string)(item),
nullptr, 0)); }
99 if (node.isSeq() ==
false)
LTHROW(
"Required links array missing or not an array");
100 for (it = node.begin(); it != node.end(); ++it)
102 cv::FileNode item = *it; cv::Point p; item >> p;
103 if (p.x < 0 || p.x >= nn || p.y < 0 || p.y >= nn)
104 LTHROW(
"Link [" << p.x <<
", " << p.y <<
"] node ID out of range [0 .. " << nn-1 <<
']');
105 links.emplace_back(std::make_pair<unsigned int, unsigned int>(p.x, p.y));
108 node = fs[
"linkColors"];
109 if (node.isSeq() ==
false)
LTHROW(
"Required linkColors array missing or not an array");
110 for (it = node.begin(); it != node.end(); ++it)
111 { cv::FileNode item = *it;
linkColors.emplace_back(std::stoul((std::string)(item),
nullptr, 0)); }
119 LINFO(
"Loaded Pose Skeleton definition with " <<
nodeNames.size() <<
" nodes, " <<
links.size() <<
" links.");
124 nodes(), links(), psd(def)
127 if (psd->nodeNames.size() != psd->nodeColors.size() || psd->links.size() != psd->linkColors.size())
128 LFATAL(
"Internal error - malformed skeleton definition");
133{
return psd->nodeNames.size(); }
137{
return psd->links.size(); }
142 if (id < psd->nodeNames.size())
return psd->nodeNames[id].c_str();
143 LFATAL(
"Given ID " <<
id <<
" too large for skeleton with " << psd->nodeNames.size() <<
" nodes");
149 if (id < psd->nodeNames.size())
return psd->nodeColors[id];
150 LFATAL(
"Given ID " <<
id <<
" too large for skeleton with " << psd->nodeNames.size() <<
" nodes");
156 if (id < psd->links.size())
return psd->linkColors[id];
157 LFATAL(
"Given ID " <<
id <<
" too large for skeleton with " << psd->links.size() <<
" links");
162{
return psd->links; }
#define JEVOIS_SHARE_PATH
Base path for shared files (e.g., neural network weights, etc)
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
std::string warnAndIgnoreException(std::string const &prefix="")
Convenience function to catch an exception, issue some LERROR (depending on type),...
#define LINFO(msg)
Convenience macro for users to print out console or syslog messages, INFO level.
std::filesystem::path absolutePath(std::filesystem::path const &root, std::filesystem::path const &path)
Compute an absolute path from two paths.
std::vector< unsigned int > nodeColors
colors of nodes (size nn)
std::vector< std::pair< unsigned int, unsigned int > > links
link definitions, each is pair of node IDs (size nl)
PoseSkeletonDefinition(std::string const &filename)
Create from a YAML file.
std::vector< std::string > nodeNames
names of nodes (size nn)
std::vector< unsigned int > linkColors
link colors (size nl)
unsigned int linkColor(unsigned int id) const
Get draw color of a node from its ID, as 0xAABBGGRR (note: returned unsigned int is the same as ImU32...
PoseSkeleton(std::shared_ptr< PoseSkeletonDefinition > def)
Constructor from a previously loaded definition.
unsigned int numSkeletonNodes() const
Get the total number of nodes in the skeleton. Node ID is from 0 to that total - 1.
std::vector< std::pair< unsigned int, unsigned int > > const & linkDefinitions() const
Get a const ref to our link definitions, useful to iterate over. Each link is <node_id_1,...
unsigned int numSkeletonLinks() const
Get the total number of links in the skeleton. Link ID is from 0 to that total - 1.
unsigned int nodeColor(unsigned int id) const
Get draw color of a node from its ID, as 0xAABBGGRR (note: returned unsigned int is the same as ImU32...
char const * nodeName(unsigned int id) const
Get the name of a node from its ID.