PosturePerfection
posture_estimator.h
Go to the documentation of this file.
1 
22 #ifndef SRC_POSTURE_ESTIMATOR_H_
23 #define SRC_POSTURE_ESTIMATOR_H_
24 
25 #include <CppTimer.h>
26 #include <RemoteNotifyBroadcast.h>
27 #include <stdio.h>
28 
29 #include <string>
30 #include <vector>
31 
33 #include "opencv2/core.hpp"
34 #include "opencv2/imgproc.hpp"
35 
41 namespace PostureEstimating {
42 
61  float upper_angle;
62  float lower_angle;
63 };
64 
68 std::string stringJoint(Joint joint);
69 
74 struct Pose {
81  std::array<ConnectedJoint, JointMax + 1> joints;
82 };
83 
91 
95 Pose createPose();
96 
100 struct PoseStatus {
105 };
106 
110 enum Colours { Red, Green, Blue, Grey };
111 
116 class DelayTimer : public CppTimer {
117  private:
118  public:
119  size_t time;
120  bool running =
121  false;
126  explicit DelayTimer(size_t time);
130  ~DelayTimer();
134  void timerEvent();
138  void countdown();
139 };
144 class MessageTimer : public CppTimer {
145  private:
146  std::vector<DelayTimer*>
147  notificationTimers;
149  RemoteNotify::Broadcast*
150  broadcaster;
151  std::string msg;
152 
153  public:
154  size_t time;
156  bool running =
157  false;
166  MessageTimer(std::vector<DelayTimer*> timers,
167  RemoteNotify::Broadcast* broadcast, std::string msg,
168  size_t time);
172  ~MessageTimer();
177  void countdown();
181  void stopCountdown();
185  void timerEvent();
186 };
187 
192 class StopTimer : public CppTimer {
193  private:
194  MessageTimer* toStop;
195 
196  public:
197  size_t time;
198  bool running =
199  false;
207  StopTimer(MessageTimer* toStop, size_t time);
211  ~StopTimer();
216  void countdown();
221  void stopCountdown();
225  void timerEvent();
226 };
227 
244  private:
249  std::array<cv::Scalar, 4> colours = {
250  cv::Scalar(255, 0, 0), cv::Scalar(0, 255, 0), cv::Scalar(0, 0, 255),
251  cv::Scalar(144, 144, 144)};
252 
256  RemoteNotify::Broadcast broadcaster;
257  DelayTimer badPostureNotificationTimer;
258  DelayTimer undefinedPostureNotificationTimer;
259  MessageTimer badPostureTimer;
260  MessageTimer undefinedPostureTimer;
261  StopTimer stopBadPostureTimer;
262  StopTimer stopUndefinedPostureTimer;
263 
273  float getLineAngle(PostProcessing::Coordinate coord1,
275 
284  Pose createPoseFromResult(PostProcessing::ProcessedResults results);
285 
292  void update_current_pose(PostProcessing::ProcessedResults results);
293 
300  void calculatePoseChanges();
301 
317  void checkPostureState();
318 
324  void calculateChangesAndCheckPosture();
325 
335  PostureEstimating::PostureState updateCurrentPoseAndCheckPosture(
337 
349  void display_current_pose(PostureEstimating::Pose current_pose,
350  cv::Mat current_frame,
365  void display_pose_changes_needed(PostureEstimating::Pose pose_changes,
367  cv::Mat current_frame);
368 
369  public:
374 
379 
384 
390 
396 
402 
410 
419 
429  bool set_pose_change_threshold(float threshold);
430 
438  float get_pose_change_threshold(void);
439 
447 
464  cv::Mat current_frame);
465 };
466 } // namespace PostureEstimating
467 #endif // SRC_POSTURE_ESTIMATOR_H_
Simple timer which just has the running flag set when running and unset when not running.
Definition: posture_estimator.h:116
~DelayTimer()
Definition: posture_estimator.cpp:386
bool running
Boolen which indicates if timer is running (True = running)
Definition: posture_estimator.h:120
void timerEvent()
Sets running flag to false.
Definition: posture_estimator.cpp:387
DelayTimer(size_t time)
Constructor for PostureEstimating::DelayTimer
Definition: posture_estimator.cpp:385
void countdown()
Starts the delay timer running.
Definition: posture_estimator.cpp:389
size_t time
The time timer runs for.
Definition: posture_estimator.h:119
Broadcasts a message using RemoteNotify::Broadcast after a time is elapsed.
Definition: posture_estimator.h:144
~MessageTimer()
Deconstructor for PostureEstimating::MessageTimer
Definition: posture_estimator.cpp:424
void timerEvent()
Definition: posture_estimator.cpp:437
bool running
Boolen which indicates if timer is running (True = running)
Definition: posture_estimator.h:156
size_t time
Definition: posture_estimator.h:154
void countdown()
Starts timer to countdown, sending a messsage at the end of the countdown.
Definition: posture_estimator.cpp:425
void stopCountdown()
Stops the countdown and doesn't send message.
Definition: posture_estimator.cpp:431
MessageTimer(std::vector< DelayTimer * > timers, RemoteNotify::Broadcast *broadcast, std::string msg, size_t time)
Constructor for PostureEstimating::MessageTimer
Definition: posture_estimator.cpp:415
This class handles representations of the user's pose and calculates any updates to their pose that i...
Definition: posture_estimator.h:243
Pose current_pose
The user's current Pose from most recent data provided.
Definition: posture_estimator.h:383
Pose pose_changes
A representation of what changes are needed to get back to ideal Pose.
Definition: posture_estimator.h:395
float pose_change_threshold
A representation of what absolute value changes for a pose is acceptably still a good pose.
Definition: posture_estimator.h:401
float get_pose_change_threshold(void)
Get the currently set pose_change_threshold. Note that this threshold is in radians and we set a maxi...
Definition: posture_estimator.cpp:329
PostureEstimating::PostureState posture_state
Whether the user is currently in a Good, Bad, Unset, Undefined or UndefinedAndUnset posture....
Definition: posture_estimator.h:409
PostureEstimator()
Construct a new PostureEstimator object.
Definition: posture_estimator.cpp:64
PoseStatus runEstimator(PostProcessing::ProcessedResults results)
Return a PoseStatus of the user's pose.
Definition: posture_estimator.cpp:333
void update_ideal_pose(PostureEstimating::Pose pose)
Calibrate the user's ideal_pose with a pose object. The ideal_pose is only updated if the posture_sta...
Definition: posture_estimator.cpp:313
void analysePosture(PostureEstimating::PoseStatus pose_status, cv::Mat current_frame)
Analyse the posture_state field of PostureEstimating::PoseStatus and use it as follows:
Definition: posture_estimator.cpp:341
Pose ideal_pose
The user's ideal Pose, expected to be generated during user calibration.
Definition: posture_estimator.h:389
~PostureEstimator()
Destroy a PostureEstimator object.
Definition: posture_estimator.cpp:86
bool set_pose_change_threshold(float threshold)
Set the pose_change_threshold to allow user configuration. Note that this threshold is in radians and...
Definition: posture_estimator.cpp:320
Timer which countdowns and stops a PostureEstimating::MessageTimer if countdown ends.
Definition: posture_estimator.h:192
void timerEvent()
Runs stopCountdown() on PostureEstimating::MessageTimer
Definition: posture_estimator.cpp:410
StopTimer(MessageTimer *toStop, size_t time)
Constructor for PostureEstimating::StopTimer
Definition: posture_estimator.cpp:393
void countdown()
Starts countdown, stopping PostureEstimating::MessageTimer if countdown reached.
Definition: posture_estimator.cpp:398
size_t time
The time to wait before stopping MessageTimer countdown.
Definition: posture_estimator.h:197
~StopTimer()
Deconstructor for PostureEstimating::StopTimer
Definition: posture_estimator.cpp:397
bool running
Boolen which indicates if timer is running (True = running)
Definition: posture_estimator.h:198
void stopCountdown()
Stops the countdown and doesn't stop PostureEstimating::MessageTimer
Definition: posture_estimator.cpp:404
Data structures used in communicating between different parts of the system.
Joint
Defines order of joints in any body part arrays.
Definition: intermediate_structures.h:66
Responsible for analysing the results of pose estimation to determine any posture changes which must ...
Definition: posture_estimator.cpp:33
Colours
Colours corresponding to PostureEstimator::colours
Definition: posture_estimator.h:110
@ Blue
Definition: posture_estimator.h:110
@ Red
Definition: posture_estimator.h:110
@ Green
Definition: posture_estimator.h:110
@ Grey
Definition: posture_estimator.h:110
Pose createPose()
Creates an empty Pose object.
Definition: posture_estimator.cpp:54
std::string stringJoint(Joint joint)
Prints human readable string for enum Joint
Definition: posture_estimator.cpp:35
PostureState
Potential states which the posture can be. Unset means that the ideal_pose has not been set by the us...
Definition: posture_estimator.h:90
@ Undefined
Definition: posture_estimator.h:90
@ Good
Definition: posture_estimator.h:90
@ Bad
Definition: posture_estimator.h:90
@ UndefinedAndUnset
Definition: posture_estimator.h:90
@ Unset
Definition: posture_estimator.h:90
Indicates position and trustworthiness of a body part node.
Definition: intermediate_structures.h:122
The PostProcessing::Coordinate of each body part.
Definition: intermediate_structures.h:139
A representation of a body part.
Definition: posture_estimator.h:58
PostProcessing::Coordinate coord
Definition: posture_estimator.h:60
Joint joint
Definition: posture_estimator.h:59
float lower_angle
Definition: posture_estimator.h:62
float upper_angle
Definition: posture_estimator.h:61
Representation of user's pose for use by the pipeline processing.
Definition: posture_estimator.h:100
PostureState posture_state
Definition: posture_estimator.h:104
Pose ideal_pose
Definition: posture_estimator.h:101
Pose pose_changes
Definition: posture_estimator.h:103
Pose current_pose
Definition: posture_estimator.h:102
The representation of a human's pose, containing all the expected ConnectedJoint
Definition: posture_estimator.h:74
std::array< ConnectedJoint, JointMax+1 > joints
Each element of this array corresponds to a body part with its connections also specifed in a Posture...
Definition: posture_estimator.h:81