public void DrawHuman(ref OPDatum datum, int bodyIndex, float scoreThres = 0) { DrawBody(ref datum, bodyIndex, scoreThres); DrawHand(ref datum, bodyIndex, scoreThres); DrawFace(ref datum, bodyIndex, scoreThres); DrawRectangles(ref datum, bodyIndex); }
private void DrawBody(ref OPDatum datum, int bodyIndex, float scoreThres) { if (datum.poseKeypoints == null || bodyIndex >= datum.poseKeypoints.GetSize(0)) { PoseParent.gameObject.SetActive(false); return; } else { PoseParent.gameObject.SetActive(true); } // Pose for (int part = 0; part < poseJoints.Count; part++) { // Joints overflow if (part >= datum.poseKeypoints.GetSize(1)) { poseJoints[part].gameObject.SetActive(false); continue; } // Compare score if (datum.poseKeypoints.Get(bodyIndex, part, 2) <= scoreThres) { poseJoints[part].gameObject.SetActive(false); } else { poseJoints[part].gameObject.SetActive(true); Vector3 pos = new Vector3(datum.poseKeypoints.Get(bodyIndex, part, 0) + 1200f, datum.poseKeypoints.Get(bodyIndex, part, 1) + 700f, -1.0f); poseJoints[part].localPosition = pos; } } }
private void DrawRectangles(ref OPDatum datum, int bodyIndex) { // Hand rect if (datum.handRectangles == null || bodyIndex >= datum.handRectangles.Count) { LHandRectangle.gameObject.SetActive(false); RHandRectangle.gameObject.SetActive(false); } else { var rects = datum.handRectangles[bodyIndex]; // Left LHandRectangle.gameObject.SetActive(true); LHandRectangle.localPosition = rects.left.center; LHandRectangle.sizeDelta = rects.left.size; // Right RHandRectangle.gameObject.SetActive(true); RHandRectangle.localPosition = rects.right.center; RHandRectangle.sizeDelta = rects.right.size; } // Face rect if (datum.faceRectangles == null || bodyIndex >= datum.faceRectangles.Count) { FaceRectangle.gameObject.SetActive(false); } else { FaceRectangle.gameObject.SetActive(true); FaceRectangle.localPosition = datum.faceRectangles[bodyIndex].center; FaceRectangle.sizeDelta = datum.faceRectangles[bodyIndex].size; } }
private void DrawFace(ref OPDatum datum, int bodyIndex, float scoreThres) { // Face if (datum.faceKeypoints == null || bodyIndex >= datum.faceKeypoints.GetSize(0)) { FaceParent.gameObject.SetActive(false); return; } else { FaceParent.gameObject.SetActive(true); for (int part = 0; part < faceJoints.Count; part++) { // Joints overflow if (part >= datum.faceKeypoints.GetSize(1)) { faceJoints[part].gameObject.SetActive(false); continue; } // Compare score if (datum.faceKeypoints.Get(bodyIndex, part, 2) <= scoreThres) { faceJoints[part].gameObject.SetActive(false); } else { faceJoints[part].gameObject.SetActive(true); Vector3 pos = new Vector3(datum.faceKeypoints.Get(bodyIndex, part, 0), datum.faceKeypoints.Get(bodyIndex, part, 1), 0f); faceJoints[part].localPosition = pos; } } } }
public void DrawHuman(ref OPDatum datum, int bodyIndex) { DrawBody(ref datum, bodyIndex); DrawHand(ref datum, bodyIndex); DrawFace(ref datum, bodyIndex); DrawRectangles(ref datum, bodyIndex); }
private void DrawBody(ref OPDatum datum, int bodyIndex, float scoreThres) { if (datum.poseKeypoints == null || bodyIndex >= datum.poseKeypoints.GetSize(0)) { PoseParent.gameObject.SetActive(false); return; } else { PoseParent.gameObject.SetActive(true); } // Pose for (int part = 0; part < poseJoints.Count; part++) { // Joints overflow if (part >= datum.poseKeypoints.GetSize(1)) { poseJoints[part].gameObject.SetActive(false); continue; } // Compare score if (datum.poseKeypoints.Get(bodyIndex, part, 2) <= scoreThres) { poseJoints[part].gameObject.SetActive(false); } else { poseJoints[part].gameObject.SetActive(true); Vector3 pos = new Vector3(datum.poseKeypoints.Get(bodyIndex, part, 0), datum.poseKeypoints.Get(bodyIndex, part, 1), 0f); poseJoints[part].localPosition = pos; //--------------This section is for PILS test: evaluation of pos-------------// //print("Part;"+part+" "+width+","+ height); //if (part == 7){ //print(UnityEditor.Handles.GetMainGameViewSize().x+ ","+UnityEditor.Handles.GetMainGameViewSize().y); //EvaluatePos.eval_pos_sync(pos); //} //--------------This section is for PILS test: evaluation of pos-------------// } } //--------------This section is for PILS test: evaluation of angle-------------// if (AnimSpeedController.clicked_start) { EvaluateAngle.Compute_OP_PseudoAngle(poseJoints); EvaluateAngle.Compute_Model_PseudoAngle(standardModel.GetComponent <ModelToBody25>().poseStandard); EvaluateAngle.ComputeScore(); } //--------------This section is for PILS test: evaluation of angle-------------// }
public void UpdateImage(ref OPDatum datum) { var data = datum.cvInputData; // width * height * 3 if (data == null || data.Empty()) { return; } int height = data.GetSize(0), width = data.GetSize(1); /* Unity does not support BGR24 yet, which is the data representation in OpenCV */ /* Here we are using RGB24 as data format, then swap R and B in shader */ texture.Resize(width, height, TextureFormat.RGB24, false); texture.LoadRawTextureData(data.ToArray()); texture.Apply(); }
public void TestAnimation(ref OPDatum datum) { if (datum.poseKeypoints == null) { obj["Take 001"].speed = 0; } else { // test 4 keypoints if (datum.poseKeypoints.Get(0, 0, 2) < 0.05f || datum.poseKeypoints.Get(0, 5, 2) < 0.05f || datum.poseKeypoints.Get(0, 6, 2) < 0.05f || datum.poseKeypoints.Get(0, 7, 2) < 0.05f) { obj["Take 001"].speed = 0; } Vector2 hhead = new Vector2(datum.poseKeypoints.Get(0, 0, 0), datum.poseKeypoints.Get(0, 0, 1)); Vector2 hlshoulder = new Vector2(datum.poseKeypoints.Get(0, 5, 0), datum.poseKeypoints.Get(0, 5, 1)); Vector2 hlelbow = new Vector2(datum.poseKeypoints.Get(0, 6, 0), datum.poseKeypoints.Get(0, 6, 1)); Vector2 hlWrist = new Vector2(datum.poseKeypoints.Get(0, 7, 0), datum.poseKeypoints.Get(0, 7, 1)); Vector2 ohead = new Vector2(transformList[0].position.x, transformList[0].position.y); Vector2 olshoulder = new Vector2(transformList[5].position.x, transformList[5].position.y); Vector2 olelbow = new Vector2(transformList[6].position.x, transformList[6].position.y); Vector2 olWrist = new Vector2(transformList[7].position.x, transformList[7].position.y); float rangeDifference = Vector2.Angle(hhead - hlshoulder, hlWrist - hlshoulder) - Vector2.Angle(ohead - olshoulder, olWrist - olshoulder); Debug.Log(Vector2.Angle(ohead - olshoulder, olWrist - olshoulder)); if (Mathf.Abs(rangeDifference) < 20.0f) { obj["Take 001"].speed = 1; } else { obj["Take 001"].speed = 0; } } }
private void DrawHand(ref OPDatum datum, int bodyIndex, float scoreThres) { // Left if (datum.handKeypoints == null || bodyIndex >= datum.handKeypoints.left.GetSize(0)) { LHandParent.gameObject.SetActive(false); } else { LHandParent.gameObject.SetActive(true); for (int part = 0; part < lHandJoints.Count; part++) { // Joints overflow if (part >= datum.handKeypoints.left.GetSize(1)) { lHandJoints[part].gameObject.SetActive(false); continue; } // Compare score if (datum.handKeypoints.left.Get(bodyIndex, part, 2) <= scoreThres) { lHandJoints[part].gameObject.SetActive(false); } else { lHandJoints[part].gameObject.SetActive(true); Vector3 pos = new Vector3(datum.handKeypoints.left.Get(bodyIndex, part, 0), datum.handKeypoints.left.Get(bodyIndex, part, 1), 0f); lHandJoints[part].localPosition = pos; } } } // Right if (datum.handKeypoints == null || bodyIndex >= datum.handKeypoints.right.GetSize(0)) { RHandParent.gameObject.SetActive(false); } else { RHandParent.gameObject.SetActive(true); for (int part = 0; part < rHandJoints.Count; part++) { // Joints overflow if (part >= datum.handKeypoints.right.GetSize(1)) { rHandJoints[part].gameObject.SetActive(false); continue; } // Compare score if (datum.handKeypoints.right.Get(bodyIndex, part, 2) <= scoreThres) { rHandJoints[part].gameObject.SetActive(false); } else { rHandJoints[part].gameObject.SetActive(true); Vector3 pos = new Vector3(datum.handKeypoints.right.Get(bodyIndex, part, 0), datum.handKeypoints.right.Get(bodyIndex, part, 1), 0f); rHandJoints[part].localPosition = pos; } } } }