Freenect.h 1.53 KB
Newer Older
1 2 3
#ifndef FREENECT_H
#define FREENECT_H

4
#include <libfreenect/libfreenect.h>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <QMutex>
#include <QScopedPointer>
#include <QSharedPointer>
#include <QThread>

class Freenect
{
public:
    Freenect();
    ~Freenect();

    bool init(int userDeviceNumber = 0);
    bool process(void);

    QSharedPointer<QByteArray> getRgbData(void);
20 21 22
    QSharedPointer<QByteArray> getRawDepthData(void);
    QSharedPointer<QByteArray> getDistanceData(void);
    QSharedPointer<QByteArray> getColoredDepthData(void);
23 24 25 26 27

    int getTiltAngle(void) const;
    void setTiltAngle(int angle);

private:
28
    static void rgbCallback(freenect_device* device, freenect_pixel* rgb, uint32_t timestamp);
29
    static void depthCallback(freenect_device* device, void* depth, uint32_t timestamp);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

    freenect_context* context;
    freenect_device* device;

    class FreenectThread : public QThread
    {
    public:
        explicit FreenectThread(freenect_device* _device);

    protected:
        virtual void run(void);

        freenect_device* device;
    };
    QScopedPointer<FreenectThread> thread;

    // tilt angle of Kinect camera
    int tiltAngle;

    // rgbd data
    char rgb[FREENECT_RGB_SIZE];
    QMutex rgbMutex;

    char depth[FREENECT_DEPTH_SIZE];
    QMutex depthMutex;

56 57 58 59 60 61
    float distance[FREENECT_FRAME_PIX];
    QMutex distanceMutex;

    char coloredDepth[FREENECT_RGB_SIZE];
    QMutex coloredDepthMutex;

62 63 64
    // accelerometer data
    short ax, ay, az;
    double dx, dy, dz;
65 66 67

    // gamma map
    unsigned short gammaTable[2048];
68 69 70
};

#endif // FREENECT_H