Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. bool KSensor::getBodyData()
  2. {
  3.     QTextStream forLog(m_log);
  4.     // Get frame
  5.     IBodyFrame* frame = NULL;
  6.     hr = m_reader->AcquireLatestFrame(&frame);
  7.     if (FAILED(hr)) {
  8.         forLog << "Failed to acquire latest frame. hr = " << hr << endl;
  9.         return false;
  10.     } else {
  11.         forLog << "Got frame. ";
  12.         INT64 relTime = 0;
  13.         hr = frame->get_RelativeTime(&relTime);
  14.  
  15.         IBody* bodies[BODY_COUNT] = { 0 };
  16.         if (FAILED(hr)) {
  17.             forLog << "Could not get relative time. hr = " << hr << endl;
  18.         } else {
  19.             forLog << "RelativeTime=" << relTime;
  20.             hr = frame->GetAndRefreshBodyData(_countof(bodies), bodies);
  21.         }
  22.  
  23.         if (FAILED(hr)) {
  24.             forLog << "Could not get and refresh body data. hr = " << hr << endl;
  25.         } else {
  26.             processBodyFrameData(bodies);
  27.         }
  28.  
  29.         for (int i = 0; i < _countof(bodies); ++i) {
  30.             safeRelease(&bodies[i]);
  31.         }
  32.         safeRelease(&frame);
  33.     }
  34.     return true;
  35. }
  36.  
  37. void KSensor::processBodyFrameData(IBody** bodies)
  38. {
  39.     QTextStream furLog(m_log);
  40.     bool discardFrame = true;
  41.     BOOLEAN isTracked;
  42.     Joint joints[JointType_Count];
  43.     JointOrientation orientations[JointType_Count];
  44.     for (int i = 0; i < BODY_COUNT; i++) {
  45.         bodies[i]->get_IsTracked(&isTracked);
  46.         if (isTracked) {
  47.             furLog << " BodyIndex=" << i;
  48.             bodies[i]->GetJoints(JointType_Count, joints);
  49.             bodies[i]->GetJointOrientations(JointType_Count, orientations);
  50.             discardFrame = false;
  51.         }
  52.     }
  53.  
  54.     if (!discardFrame) {
  55.         m_acceptedFrames++;
  56.         furLog << " Frame=" << m_acceptedFrames;
  57.  
  58.         if (m_frameBegin != 0) m_frameEnd = clock();
  59.         m_totalSeconds += double(m_frameEnd - m_frameBegin) / CLOCKS_PER_SEC;
  60.         furLog << " Seconds=" << m_totalSeconds;
  61.  
  62.         m_skeleton.addFrame(joints, orientations, m_totalSeconds, m_isRecording);
  63.         //addMarkerData();
  64.         calculateFPS();
  65.         furLog << " FPS=" << m_fps << endl;
  66.         m_frameBegin = clock();
  67.     } else {
  68.         furLog << " Frame dropped." << endl;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement