private void Update() { // New data received if (OPWrapper.OPGetOutput(out datum)) { // Draw human in data for (int i = 0; i < humans.Count; i++) { humans[i].DrawHuman(ref datum, i); } // Draw image imageRenderer.UpdateImage(ref datum); // Calculate framerate if (lastFrameTime > 0f) { if (avgFrameTime < 0f) { avgFrameTime = Time.time - lastFrameTime; } else { avgFrameTime = Mathf.Lerp(Time.time - lastFrameTime, avgFrameTime, frameRateSmoothRatio); avgFrameRate = 1f / avgFrameTime; } } lastFrameTime = Time.time; } }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } // New data received if (OPWrapper.OPGetOutput(out datum)) { // Draw human in data int i = 0; foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>()) { human.DrawHuman(ref datum, i++, renderThreshold); animationTest.TestAnimation(ref datum); } // Calculate framerate if (lastFrameTime > 0f) { if (avgFrameTime < 0f) { avgFrameTime = Time.time - lastFrameTime; } else { avgFrameTime = Mathf.Lerp(Time.time - lastFrameTime, avgFrameTime, frameRateSmoothRatio); avgFrameRate = 1f / avgFrameTime; } } lastFrameTime = Time.time; fpsText.text = avgFrameRate.ToString("F1") + " FPS"; } }
private void Update() { // Update state in UI stateText.text = OPWrapper.state.ToString(); // Try getting new frame if (OPWrapper.OPGetOutput(out datum)) // true: has new frame data // Update background image { bgImageRenderer.UpdateImage(datum.cvInputData); // Rescale output UI Vector2 outputSize = outputTransform.sizeDelta; Vector2 screenSize = OpenPoseCamera.pixelRect.size; float scale = Mathf.Min(screenSize.x / outputSize.x, screenSize.y / outputSize.y); outputTransform.localScale = new Vector3(scale, scale, scale); // Update number of people in UI if (datum.poseKeypoints == null || datum.poseKeypoints.Empty()) { numberPeople = 0; } else { numberPeople = datum.poseKeypoints.GetSize(0); } peopleText.text = "People: " + numberPeople; // Draw human while (humanContainer.childCount < numberPeople) // Make sure no. of HumanControllers no less than numberPeople { humanPrefab.name = humanPrefab.name + "_" + numberPeople.ToString(); Instantiate(humanPrefab, humanContainer); } int i = 0; foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>()) { // When i >= no. of human, the human will be hidden human.DrawHuman(ref datum, i++, renderThreshold); } // Update framerate in UI frameTimeQueue.Enqueue(Time.time); frameCounter++; if (frameTimeQueue.Count > queueMaxCount) // overflow { frameTimeQueue.Dequeue(); } if (frameCounter >= queueMaxCount || frameTimeQueue.Count <= 5) // update frame rate { frameCounter = 0; avgFrameRate = frameTimeQueue.Count / (Time.time - frameTimeQueue.Peek()); fpsText.text = avgFrameRate.ToString("F1") + " FPS"; } } }
private void Update() { // New data received if (OPWrapper.OPGetOutput(out datum)) { // Draw human in data int i = 0; foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>()) { human.DrawHuman(ref datum, i++, renderThreshold); } // Draw image imageRenderer.UpdateImage(datum.cvInputData); // Number of people if (datum.poseKeypoints == null || datum.poseKeypoints.Empty()) { numberPeople = 0; } else { numberPeople = datum.poseKeypoints.GetSize(0); } peopleText.text = "People: " + numberPeople; // Calculate framerate if (lastFrameTime > 0f) { if (avgFrameTime < 0f) { avgFrameTime = Time.time - lastFrameTime; } else { avgFrameTime = Mathf.Lerp(Time.time - lastFrameTime, avgFrameTime, frameRateSmoothRatio); avgFrameRate = 1f / avgFrameTime; } } lastFrameTime = Time.time; fpsText.text = avgFrameRate.ToString("F1") + " FPS"; } }
private void Update() { // Try getting new frame if (OPWrapper.OPGetOutput(out datum)) // true: has new frame data // Draw human in data { int i = 0; foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>()) { human.DrawHuman(ref datum, i++, renderThreshold); } // Draw image imageRenderer.UpdateImage(datum.cvInputData); // Number of people if (datum.poseKeypoints == null || datum.poseKeypoints.Empty()) { numberPeople = 0; } else { numberPeople = datum.poseKeypoints.GetSize(0); } peopleText.text = "People: " + numberPeople; // Calculate framerate frameTimeQueue.Enqueue(Time.time); frameCounter++; if (frameTimeQueue.Count > queueMaxCount) // overflow { frameTimeQueue.Dequeue(); } if (frameCounter >= queueMaxCount || frameTimeQueue.Count <= 5) // update frame rate { frameCounter = 0; avgFrameRate = frameTimeQueue.Count / (Time.time - frameTimeQueue.Peek()); fpsText.text = avgFrameRate.ToString("F1") + " FPS"; } } }
private void Update() { // Update state in UI stateText.text = OPWrapper.state.ToString(); // Try getting new frame if (OPWrapper.OPGetOutput(out datum)) // true: has new frame data //Debug.Log(datum.poseKeypoints); // Update background image { bgImageRenderer.UpdateImage(datum.cvInputData); // Rescale output UI Vector2 outputSize = outputTransform.sizeDelta; Vector2 screenSize = Camera.main.pixelRect.size; float scale = Mathf.Min(screenSize.x / outputSize.x, screenSize.y / outputSize.y); outputTransform.localScale = new Vector3(scale, scale, scale); // Update number of people in UI if (datum.poseKeypoints == null || datum.poseKeypoints.Empty()) { numberPeople = 0; if (count > 30) { patientInfo.GetComponent <Text>().text = ""; patientLabels.GetComponent <Text>().text = ""; //redScene.SetActive(false); labelBG.SetActive(false); count = 0; flag = false; } count++; chk_count = 0; } else { if (flag == false) { randomIdx = Random.Range(0, 4); //patientName = names[randomIdx]; //patientDisease = diseases[randomIdx]; age = Random.Range(50, 100); flag = true; } count = 0; numberPeople = datum.poseKeypoints.GetSize(0); Discriminate dc = ShowListContentsInTheDebugLog(datum.poseKeypoints); if (dc.status) { nfPos = patientInfo.transform.position; nfPos.x = -90; nfPos.y = 80; //Debug.Log(nfPos.x); //Debug.Log(nfPos.y); patientInfo.transform.position = nfPos; patientInfo.GetComponent <Text>().text = "Fallen"; patientLabels.GetComponent <Text>().text = "Name: Ken\nAge: 72\nDisease: cancer"; //redScene.SetActive(true); labelBG.SetActive(true); //GameObject fps = GameObject.Find("FPS"); //Debug.Log(fps.transform.position.x); //Debug.Log(fps.transform.position.y); //GameObject ppl = GameObject.Find("People"); //Debug.Log(ppl.transform.position.x); //Debug.Log(ppl.transform.position.y); } chk_count++; } peopleText.text = "People: " + numberPeople; // Draw human while (humanContainer.childCount < numberPeople) { // Make sure no. of HumanControllers no less than numberPeople Instantiate(humanPrefab, humanContainer); } int i = 0; foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>()) { // When i >= no. of human, the human will be hidden human.DrawHuman(ref datum, i++, renderThreshold); } // Update framerate in UI frameTimeQueue.Enqueue(Time.time); frameCounter++; if (frameTimeQueue.Count > queueMaxCount) // overflow { frameTimeQueue.Dequeue(); } if (frameCounter >= queueMaxCount || frameTimeQueue.Count <= 5) // update frame rate { frameCounter = 0; avgFrameRate = frameTimeQueue.Count / (Time.time - frameTimeQueue.Peek()); fpsText.text = avgFrameRate.ToString("F1") + " FPS"; } } }