После того, как много копал (так что я вас не виню), я нашел следующее, что, я думаю, именно то, что вы искали в этом форуме :
Существует Пример обнаружения объекта OpenCv .
Самый интересный для вас метод, я думаю, был бы самым нижним:
/// <summary>
/// Results the rects to result game objects.
/// </summary>
/// <param name="rects">Rects.</param>
/// <param name="color">Color.</param>
/// <param name="zPos">Z position.</param>
private void ResultRectsToResultGameObjects (IList<object> rects, Color color, float zPos)
{
Vector3[] resultPoints = new Vector3[rects.Count];
float textureWidth = GetComponent<Renderer> ().material.mainTexture.width;
float textureHeight = GetComponent<Renderer> ().material.mainTexture.height;
Matrix4x4 transCenterM = Matrix4x4.TRS (new Vector3 (-textureWidth / 2, -textureHeight / 2, 0), Quaternion.identity, new Vector3 (1, 1, 1));
Vector3 translation = new Vector3 (gameObject.transform.localPosition.x, gameObject.transform.localPosition.y, gameObject.transform.localPosition.z);
Quaternion rotation = Quaternion.Euler (gameObject.transform.localEulerAngles.x, gameObject.transform.localEulerAngles.y, gameObject.transform.localEulerAngles.z);
Vector3 scale = new Vector3 (gameObject.transform.localScale.x / textureWidth, gameObject.transform.localScale.y / textureHeight, 1);
Matrix4x4 trans2Dto3DM = Matrix4x4.TRS (translation, rotation, scale);
for (int i = 0; i < resultPoints.Length; i++)
{
IDictionary rect = (IDictionary)rects [i];
//get center of rect.
resultPoints [i] = new Vector3 ((long)rect ["x"] + (long)rect ["width"] / 2, (long)rect ["y"] + (long)rect ["height"] / 2, 0);
//translate origin to center.
resultPoints [i] = transCenterM.MultiplyPoint3x4 (resultPoints [i]);
//transform from 2D to 3D
resultPoints [i] = trans2Dto3DM.MultiplyPoint3x4 (resultPoints [i]);
//Add resultGameObject.
GameObject result = Instantiate (resultPrefab, resultPoints [i], Quaternion.identity) as GameObject;
result.transform.parent = gameObject.transform;
result.transform.localPosition = new Vector3 (result.transform.localPosition.x, result.transform.localPosition.y, zPos);
result.transform.localEulerAngles = new Vector3 (0, 0, 0);
result.transform.localScale = new Vector3 ((long)rect ["width"] / textureWidth, (long)rect ["height"] / textureHeight, 20);
result.GetComponent<Renderer> ().material.color = color;
resultGameObjects.Add (result);
}
}
Конечно, я не проверял это, но похоже, что он делает то, что вы хотите: размещать объекты напозиции rects.
И, конечно, вам придется принять его в соответствии со своими потребностями, но я надеюсь, что это хорошая отправная точка для вас.