// 處理多動作配對失敗,返回 "誤差最小" 的那個動作,推測是做該動作但失敗 public DetectSkeleton thisOneFailed(DetectSkeleton detects) { switch (detects) { case DetectSkeleton.Game1: return(compareAccuracy(DetectSkeleton.LeftSingleJump, DetectSkeleton.RightSingleJump, DetectSkeleton.RaiseTwoHand)); case DetectSkeleton.Game2: return(compareAccuracy(DetectSkeleton.SlidingSideShift, DetectSkeleton.LeftThrowBall, DetectSkeleton.RightThrowBall)); case DetectSkeleton.Game3: return(compareAccuracy(DetectSkeleton.Sit, DetectSkeleton.LeftKick, DetectSkeleton.RightKick)); case DetectSkeleton.Game4: return(compareAccuracy(DetectSkeleton.Run, DetectSkeleton.LeftCrossJump, DetectSkeleton.RightCrossJump)); case DetectSkeleton.Game5: return(compareAccuracy(DetectSkeleton.LeftHit, DetectSkeleton.RightHit, DetectSkeleton.DoubleJump)); case DetectSkeleton.Game6: return(compareAccuracy(DetectSkeleton.LeftDribble, DetectSkeleton.RightDribble, DetectSkeleton.LeftSingleStand, DetectSkeleton.RightSingleStand)); case DetectSkeleton.CrossJump: return(compareAccuracy(DetectSkeleton.LeftCrossJump, DetectSkeleton.RightCrossJump)); case DetectSkeleton.SingleJump: return(compareAccuracy(DetectSkeleton.LeftSingleJump, DetectSkeleton.RightSingleJump)); default: return(compareAccuracy(detects)); } }
void setScore(int _order, DetectSkeleton _movement, int _score, int _total) { string _type = movement_name[_movement]; #region 限制各項得分不高於總要求次數 if (_score > _total) { _score = _total; } #endregion string _score_summary = string.Format("{0} / {1}", _score, _total); if (_order == 1) { title1.text = _type; score1.text = _score_summary; } else if (_order == 2) { title2.text = _type; score2.text = _score_summary; } else if (_order == 3) { title3.text = _type; score3.text = _score_summary; } }
public void endMatch(DetectSkeleton _detect_skeleton, string file_id) { print("endMatch"); // 設置結束時間 record_data.setEndTime(); // 記錄三維歐拉距離 string remark = string.Format("{0:F4}-{1:F4}-{2:F4}", max_x_distance, max_y_distance, max_z_distance); record_data.setRemark(remark); // 動作流水編號,自動增加 number_satge++; // 停止紀錄骨架 is_recording = false; // 停止動作提示 hint.stopVideo(); //動作提示、紀錄數據 DetectSkeleton?result = whichOnePass(_detect_skeleton); DetectSkeleton detect; if (result == null) { // 如果都失敗 detect = thisOneFailed(detect_skeleton); } else { // 如果其中一個成功 detect = (DetectSkeleton)result; } Movement _movement = movement_map[detect]; record_data.setType(detect); record_data.setThreshold(_movement.getThresholds()); record_data.setAccuracy(_movement.getAccuracy()); // 取消偵測 detect_skeleton = DetectSkeleton.None; // 完成數據紀錄後,還原回尚未配對狀態 resetState(); // 紀錄相關數據並寫出 RecordData.save(file_id, record_data); record_data = new RecordData(); }
// 檢查是否所有動作皆通過 bool compare(DetectSkeleton skeleton) { bool _pass = true; Movement _movement = movement_map[skeleton]; int len = _movement.getThresholdNumber(), i; for (i = 0; i < len; i++) { _pass &= _movement.isMatched(i); } return(_pass); }
void setVideo(string _place, DetectSkeleton _type) { string _video_path = string.Format("_Video/{0}", _type); if (_place.Equals("left")) { left_video.clip = Resources.Load <VideoClip>(_video_path); } else { right_video.clip = Resources.Load <VideoClip>(_video_path); } }
public void selectHint(DetectSkeleton _type) { DetectSkeleton _left_type = _type, _right_type = _type; left_hint.SetActive(true); right_hint.SetActive(true); switch (_type) { case DetectSkeleton.Game1: //return whichPass(DetectSkeleton.LeftSingleJump, DetectSkeleton.RightSingleJump, DetectSkeleton.RaiseTwoHand); _left_type = DetectSkeleton.SingleJump; _right_type = DetectSkeleton.RaiseTwoHand; break; case DetectSkeleton.Game2: //return whichPass(DetectSkeleton.SlidingSideShift, DetectSkeleton.LeftThrowBall, DetectSkeleton.RightThrowBall); _left_type = DetectSkeleton.ThrowBall; _right_type = DetectSkeleton.SlidingSideShift; break; case DetectSkeleton.Game3: //return whichPass(DetectSkeleton.Sit, DetectSkeleton.LeftKick, DetectSkeleton.RightKick); _left_type = DetectSkeleton.Sit; _right_type = DetectSkeleton.Kick; break; case DetectSkeleton.Game4: //return whichPass(DetectSkeleton.Run, DetectSkeleton.LeftCrossJump, DetectSkeleton.RightCrossJump); _left_type = DetectSkeleton.Run; _right_type = DetectSkeleton.CrossJump; break; case DetectSkeleton.Game5: //return whichPass(DetectSkeleton.LeftHit, DetectSkeleton.RightHit, DetectSkeleton.DoubleJump); _left_type = DetectSkeleton.Hit; _right_type = DetectSkeleton.DoubleJump; break; case DetectSkeleton.Game6: //return whichPass(DetectSkeleton.LeftDribble, DetectSkeleton.RightDribble, DetectSkeleton.LeftSingleStand, DetectSkeleton.RightSingleStand); _left_type = DetectSkeleton.Dribble; _right_type = DetectSkeleton.SingleStand; break; } setVideo("left", _left_type); setVideo("right", _right_type); }
void setMovement(GameObject _title_text, GameObject _score_text, DetectSkeleton _skeleton) { // NullReferenceException try { setScore( _title_text, _score_text, ScoreBoard.movement_name[_skeleton], formatActionScore(_skeleton)); } catch (NullReferenceException nre) { print(nre.Message); setScore( _title_text, _score_text, ScoreBoard.movement_name[_skeleton], formatActionScore(0)); } }
public void startMatch(DetectSkeleton _detect_skeleton) { print(string.Format("startMatch:{0}", _detect_skeleton)); // 開始偵測指定動作 detect_skeleton = _detect_skeleton; record_data = new RecordData(); guid = record_data.guid; // 開始紀錄數據 stage = string.Format("{0}-{1}-{2}", story_satge, game_satge, number_satge); record_data.setStage(stage); record_data.setStartTime(); // 開始記錄骨架資訊 is_recording = true; // 開始動作提示 hint.selectHint(detect_skeleton); }
// 比對動作 void compareMovement(DetectSkeleton check_pose) { try { Movement _movement = movement_map[check_pose]; PoseModelHelper[] poseModels = _movement.getModels(); float[] thresholds = _movement.getThresholds(); int i, len = _movement.getMovementNumber(); float acc; for (i = 0; i < len; i++) { acc = getAccuracy(poseModels[i], _movement.getComparingParts()); message = string.Format("type:{0}[{1}], acc: {2:F4}, threshold: {3:F4} ", check_pose, i, _movement.getAccuracy(i), thresholds[i]); print(message); // 記錄各個分解動作的最高值 _movement.setAccuracy(i, Mathf.Max(acc, _movement.getAccuracy(i))); // 正確率超過門檻值,則 matchMap 記錄通過 if (acc > thresholds[i]) { _movement.setMatched(i, true); } } // 當所有動作皆通過 if (compare(check_pose)) { // 任一動作完成偵測,停止偵測 detect_skeleton = DetectSkeleton.None; } } catch (KeyNotFoundException) { print(string.Format("No {0} in movement_map", check_pose)); } }
string formatActionScore(DetectSkeleton _skeleton) { float _score; switch (_skeleton) { case DetectSkeleton.SingleJump: _score = GameInfo.movement_count[DetectSkeleton.LeftSingleJump] + GameInfo.movement_count[DetectSkeleton.RightSingleJump]; break; default: _score = GameInfo.movement_count[_skeleton]; break; } if (_score > N_ACTION) { _score = N_ACTION; } return(string.Format("{0} / {1}", _score, N_ACTION)); }
// 比對動作 + 額外條件 void compareMovement(DetectSkeleton check_pose, float additional_accuracy) { try { Movement _movement = movement_map[check_pose]; PoseModelHelper[] poseModels = _movement.getModels(); float[] thresholds = _movement.getThresholds(); int i, len = _movement.getMovementNumber(); float acc; for (i = 0; i < len; i++) { acc = getAccuracy(poseModels[i], _movement.getComparingParts()); message = string.Format("type:{0}[{1}], acc: {2:F4}, threshold: {3:F4} ", check_pose, i, _movement.getAccuracy(i), thresholds[i]); print(message); // 記錄各個分解動作的最高值 _movement.setAccuracy(i, Mathf.Max(acc, _movement.getAccuracy(i))); // 若正確率超過門檻值 if (acc > thresholds[i]) { // 令該動作狀態為通過 _movement.setMatched(i, true); } } // 附加額外通關條件 if (_movement.hasAddtionalCondition()) { // 取得正確率最高值 acc = Mathf.Max(additional_accuracy, _movement.getAccuracy(i)); // 確保正確率最大值為 1(額外條件為距離,因此正確率可能超過 1) acc = Mathf.Min(1f, acc); // 設定動作正確率 _movement.setAccuracy(i, acc); //print(string.Format("additional_accuracy: {0:F4}", acc)); // 若正確率超過門檻值 if (acc >= thresholds[i]) { // 令該動作狀態為通過 _movement.setMatched(i, true); //print(string.Format("additional: i={0}, threshold={1:F4}, acc={2:F4}", // i, thresholds[i], acc)); } } // 當所有動作皆通過 if (compare(check_pose)) { // 任一動作完成偵測,停止偵測 detect_skeleton = DetectSkeleton.None; } } catch (KeyNotFoundException) { print(string.Format("No {0} in movement_map", check_pose)); } }
public void setType(DetectSkeleton type) { this.type = string.Format("{0}", type); }
public void setMovementSelection(DetectSkeleton _movement, GameItem[] _selection) { movement = string.Format("{0}", _movement); selection = multiItems(_selection); }
public void setScore2(DetectSkeleton _movement, int _score, int _total) { setScore(2, _movement, _score, _total); }