|
| 1 | +#ifndef SENSORDEVICE_H |
| 2 | +#define SENSORDEVICE_H |
| 3 | + |
| 4 | +#include <QObject> |
| 5 | +#include <QThread> |
| 6 | + |
| 7 | +#include <OpenNI.h> |
| 8 | +#include <NiTE.h> |
| 9 | +#include <opencv2/opencv.hpp> |
| 10 | + |
| 11 | +#include <QQuaternion> |
| 12 | +#include <QVector3D> |
| 13 | +#include <QVector2D> |
| 14 | + |
| 15 | +#include <QDebug> |
| 16 | + |
| 17 | +#define SENSOR_WIDTH 640 |
| 18 | +#define SENSOR_HEIGHT 480 |
| 19 | + |
| 20 | +namespace IMAGE { enum Mode { DEPTH = 0, COLOR = 1, IR = 2, }; } |
| 21 | +Q_DECLARE_METATYPE(IMAGE::Mode) |
| 22 | + |
| 23 | +namespace POSE { enum Type { PSI = 0, ARMS_CROSSED = 1, }; } |
| 24 | +Q_DECLARE_METATYPE(POSE::Type) |
| 25 | + |
| 26 | +typedef struct { QVector3D minimum; QVector3D maximum; } RealWorldBoundingBox; |
| 27 | +typedef struct { QVector2D minimum; QVector2D maximum; } ProjectiveBoundingBox; |
| 28 | +typedef struct |
| 29 | +{ |
| 30 | + cv::Mat pixelmap; |
| 31 | + QVector2D projective_center_of_mass; |
| 32 | + QVector3D real_world_center_of_mass; |
| 33 | + ProjectiveBoundingBox projective_bounding_box; |
| 34 | + RealWorldBoundingBox real_world_bounding_box; |
| 35 | +} UserMap; |
| 36 | +Q_DECLARE_METATYPE(UserMap) |
| 37 | + |
| 38 | +typedef struct { QVector2D position; } ProjectiveJoint; |
| 39 | +typedef struct |
| 40 | +{ |
| 41 | + ProjectiveJoint head; ProjectiveJoint neck; |
| 42 | + ProjectiveJoint left_shoulder; ProjectiveJoint left_elbow; ProjectiveJoint left_hand; |
| 43 | + ProjectiveJoint right_shoulder; ProjectiveJoint right_elbow; ProjectiveJoint right_hand; |
| 44 | + ProjectiveJoint torso; |
| 45 | + ProjectiveJoint left_hip; ProjectiveJoint left_knee; ProjectiveJoint left_foot; |
| 46 | + ProjectiveJoint right_hip; ProjectiveJoint right_knee; ProjectiveJoint right_foot; |
| 47 | +} ProjectiveSkeleton; |
| 48 | +Q_DECLARE_METATYPE(ProjectiveSkeleton) |
| 49 | + |
| 50 | +typedef struct { QQuaternion orientation; QVector3D position; } RealWorldJoint; |
| 51 | +typedef struct |
| 52 | +{ |
| 53 | + RealWorldJoint head; RealWorldJoint neck; |
| 54 | + RealWorldJoint left_shoulder; RealWorldJoint left_elbow; RealWorldJoint left_hand; |
| 55 | + RealWorldJoint right_shoulder; RealWorldJoint right_elbow; RealWorldJoint right_hand; |
| 56 | + RealWorldJoint torso; |
| 57 | + RealWorldJoint left_hip; RealWorldJoint left_knee; RealWorldJoint left_foot; |
| 58 | + RealWorldJoint right_hip; RealWorldJoint right_knee; RealWorldJoint right_foot; |
| 59 | +} RealWorldSkeleton; |
| 60 | +Q_DECLARE_METATYPE(RealWorldSkeleton) |
| 61 | + |
| 62 | +Q_DECLARE_METATYPE(cv::Mat) |
| 63 | + |
| 64 | +class SensorDevice : public QThread |
| 65 | +{ |
| 66 | + Q_OBJECT |
| 67 | +public: |
| 68 | + explicit SensorDevice(QObject *parent = 0, QString devicePath = QString()); |
| 69 | + ~SensorDevice(void); |
| 70 | + |
| 71 | + bool initSensor(int depthXres = 640, |
| 72 | + int depthYres = 480, |
| 73 | + int depthFPS = 30, |
| 74 | + int rgbXres = 640, |
| 75 | + int rgbYres = 480, |
| 76 | + int rgbFPS = 30, |
| 77 | + int irXres = 640, |
| 78 | + int irYres = 480, |
| 79 | + int irFPS = 30); |
| 80 | + bool stopSensor(void); |
| 81 | + |
| 82 | +private: |
| 83 | + QString m_devicePath; |
| 84 | + bool m_isActive, |
| 85 | + m_isDepth_running, |
| 86 | + m_isRGB_running, |
| 87 | + m_isIR_running; |
| 88 | + |
| 89 | + openni::Device m_device; |
| 90 | + openni::VideoStream m_videoDepth, m_videoColor, m_videoIR; |
| 91 | + openni::VideoStream** m_videoStreamDepth, **m_videoStreamColor, **m_videoStreamIR; |
| 92 | + nite::HandTracker m_handTracker; |
| 93 | + nite::UserTracker m_userTracker; |
| 94 | + |
| 95 | + RealWorldJoint convertSkeletonJointToRealWorld(const nite::SkeletonJoint); |
| 96 | + ProjectiveJoint convertSkeletonJointToProjective(const nite::SkeletonJoint); |
| 97 | + |
| 98 | +public slots: |
| 99 | + void run(void); |
| 100 | + |
| 101 | +signals: |
| 102 | + void hand_init(short); |
| 103 | + void hand_coordinate(short, QVector3D); |
| 104 | + void hand_stop(short); |
| 105 | + |
| 106 | + void user_init(short); |
| 107 | + void user_map(short, UserMap); |
| 108 | + void user_projective_skeleton(short, ProjectiveSkeleton); |
| 109 | + void user_real_world_skeleton(short, RealWorldSkeleton); |
| 110 | + void user_pose(short, POSE::Type); |
| 111 | + void user_stop(short); |
| 112 | + |
| 113 | + void image_data(IMAGE::Mode, cv::Mat); |
| 114 | +}; |
| 115 | + |
| 116 | +#endif // SENSORDEVICE_H |
0 commit comments