private void UpdateFromBuffer() { // The buffer is full FastPoseFrame receivedFrame = new FastPoseFrame(this.MessageBuffer); OnSync?.Invoke(this, new OnSyncEventArgs(receivedFrame)); this.UpdateID = receivedFrame.ID; if (this.UpdateID == STOP_CODE_ID) { // We won't be getting more! Disconnect(); } }
public void SyncFrom(FastPoseFrame pose) { for (int i = 0; i < AllJoints.Length; i++) { AllJoints[i].transform.position = this.Image2World(pose.GetPosition(i)); if (pose.GetConfidence(i) < ConfidenceThreshold) { AllJoints[i].SetActive(false); } else { AllJoints[i].SetActive(true); } } }
private void UpdateCurrentPose(FastPoseFrame syncData) { Vector2[] prevPositions = new Vector2[NumBones]; // Save all the previous positions in local space for (int i = 0; i < NumBones - 1; i++) { // parent + "local" position = "global" position prevPositions[i] = currentRawPositions[i] - currentRawPositions[(int)jointParents[i]]; } for (int i = 0; i < FastPoseFrame.NUM_KEYPOINTS; i++) { float score = syncData.GetConfidence(i); if (score < ConfidenceThreshold) { // We probably can't see this joint. Use the same local position, with the parent's // new global position currentRawPositions[i] = currentRawPositions[(int)jointParents[i]] + prevPositions[i]; } else { // We see this joint! Update with data from the frame if (currentScores[i] > ConfidenceThreshold) { // We saw it before, smooth the two together currentRawPositions[i] = Vector2.Lerp(currentRawPositions[i], syncData.GetWorldPosition(i), SmoothingFactor); } else { // We didn't see it before, use only new data currentRawPositions[i] = syncData.GetWorldPosition(i); } } currentScores[i] = score; } // Estimate the "root" position too as just the average of the hips/shoulders currentRawPositions[(int)ESSDJointName.ROOT] = ( currentRawPositions[(int)ESSDJointName.RIGHT_SHOULDER] + currentRawPositions[(int)ESSDJointName.LEFT_SHOULDER] + currentRawPositions[(int)ESSDJointName.RIGHT_HIP] + currentRawPositions[(int)ESSDJointName.LEFT_HIP] ) / 4.0f; currentScores[(int)ESSDJointName.ROOT] = 1.0f; }
public OnSyncEventArgs(FastPoseFrame SyncData) { this.SyncData = SyncData; }