private void DrawRects(Rect[] rects, float imageWidth, float imageHeight) { UnityEngine.Rect[] overlayRects = new UnityEngine.Rect[rects.Length]; for (int i = 0; i < rects.Length; i++) { overlayRects[i] = new UnityEngine.Rect(rects[i].x / imageWidth , rects[i].y / imageHeight , rects[i].width / imageWidth , rects[i].height / imageHeight); } rectOverlay.DrawRects(overlayRects); }
private void DrawRects(List <TrackedObject> objList, float imageWidth, float imageHeight) { TrackedObject[] objs = objList.ToArray(); UnityEngine.Rect[] overlayRects = new UnityEngine.Rect[objs.Length]; // Cleanup missing face Dictionary <int, Person> tmpPeople = new Dictionary <int, Person>(); for (int i = 0; i < objs.Length; i++) { if (people.ContainsKey(objs[i].id)) { //Debug.Log("people[objs[i].id].recognizeState" + people[objs[i].id].recognizeState); tmpPeople.Add(objs[i].id, people[objs[i].id]); } } people.Clear(); people = tmpPeople; // Retrun fail recognize for (int i = 0; i < objs.Length; i++) { if (!people.ContainsKey(objs[i].id)) { Person person = new Person(objs[i].position, grayMat4Thread); WebRequestClient wrc = new WebRequestClient(); StartCoroutine(wrc.Post(person)); people.Add(objs[i].id, person); } else { if (people[objs[i].id].recognizeState == Person.RecognizeState.NOTRECOGNIZED) { if (people[objs[i].id].failReturnCount < FAILRETURNCOUNT) { // delay 24 frame for next recognize if (people[objs[i].id].delayFrameCount > SKIPFRAMEPREFAIL) { people[objs[i].id].UpdateFace(objs[i].position, grayMat4Thread); WebRequestClient wrc = new WebRequestClient(); StartCoroutine(wrc.Post(people[objs[i].id])); people[objs[i].id].delayFrameCount = 0; people[objs[i].id].failReturnCount++; } else { people[objs[i].id].delayFrameCount++; } } } } var rect = rectangleTracker.GetSmoothingRect(i); //var rect = objs[i].position; overlayRects[i] = new UnityEngine.Rect(rect.x / imageWidth , rect.y / imageHeight , rect.width / imageWidth , rect.height / imageHeight); } GameObject[] rst = rectOverlay.DrawRects(overlayRects); // Assume target spawned prefab are contain PersonOverlayer. if (rst != null) { int cnt = rst.Length; PersonOverlayer[] personOverlays = new PersonOverlayer[cnt]; for (int i = 0; i < cnt; i++) { personOverlays[i] = rst[i].GetComponent <PersonOverlayer>(); string username = ""; string detail = ""; Color color = Color.yellow; if (people.ContainsKey(objs[i].id)) { username = people[objs[i].id].username; detail = people[objs[i].id].detail; color = people[objs[i].id].color; } //Debug.Log("username is " + username); personOverlays[i].SetText(username, detail, color); } } }