Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include "KinectGrabThread.hpp"
  2. #include "MainWindow.hpp"
  3.  
  4. namespace lfb
  5. {
  6.  
  7. KinectGrabThread::KinectGrabThread( MainWindow& app )
  8.     : QThread()
  9.     , mApp( app )
  10.     , mEnvironment()
  11.     , mDevice( mEnvironment.createDevice< lfb::Device >( 0 ) )
  12.     , mRGBBuffer( FREENECT_VIDEO_RGB_SIZE )
  13.     , mDepthBuffer( FREENECT_VIDEO_RGB_SIZE )
  14. {
  15.     mDevice.setDepthFormat( FREENECT_DEPTH_11BIT );
  16.     mDevice.setVideoFormat( FREENECT_VIDEO_RGB );
  17.     mDevice.startVideo();
  18.     mDevice.startDepth();
  19.  
  20.     connect(this, SIGNAL(ImagesGrabbed(const std::vector< uint8_t >&, const std::vector< uint8_t >&)), &app,
  21.             SLOT(RefreshKinectData( const std::vector< uint8_t >&, const std::vector< uint8_t >& )));
  22.  
  23.     QTimer* timer = new QTimer(this);
  24.     connect(timer, SIGNAL(timeout()), this, SLOT(GrabImages()));
  25.     timer->start( 200 ); // 25 FPS
  26. }
  27.  
  28. KinectGrabThread::~KinectGrabThread()
  29. {
  30.     mDevice.stopVideo();
  31.     mEnvironment.deleteDevice( 0 );
  32. }
  33.  
  34. void KinectGrabThread::LockImages()
  35. {
  36.     mMutex.lock();
  37. }
  38.  
  39. void KinectGrabThread::UnlockImages()
  40. {
  41.     mMutex.unlock();
  42. }
  43.  
  44. void KinectGrabThread::run()
  45. {
  46.     exec();
  47. }
  48.  
  49. void KinectGrabThread::GrabImages()
  50. {
  51.     LockImages();
  52.     mDevice.GetRGBImage( mRGBBuffer );
  53.     mDevice.GetDepthImage( mDepthBuffer );
  54.     UnlockImages();
  55.     emit ImagesGrabbed( mRGBBuffer, mDepthBuffer );
  56.  
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement