Exemple #1
0
    public void OnRenderObject()
    {
        if (textureHolder.GetTexture() == null)
        {
            return;
        }
        var texSize = new Vector2(textureHolder.GetTexture().width, textureHolder.GetTexture().height);

        var contours = finder.Contours;
        var area     = EMath.GetShrinkFitSize(texSize, screenSize);

        GL.PushMatrix();
        GL.MultMatrix(transform.localToWorldMatrix);
        material.SetPass(0);
        foreach (var contour in contours)
        {
            GL.Begin(GL.LINE_STRIP);
            GL.Color(color);
            var rect = OpenCVUtils.GetRect(contour);
            var p1   = OpenCVUtils.GetUnityCoordinateSystemPosition(new Vector2(rect.x, rect.y), texSize, area);
            var p2   = OpenCVUtils.GetUnityCoordinateSystemPosition(new Vector2(rect.x + rect.width, rect.y), texSize, area);
            var p3   = OpenCVUtils.GetUnityCoordinateSystemPosition(new Vector2(rect.x + rect.width, rect.y + rect.height), texSize, area);
            var p4   = OpenCVUtils.GetUnityCoordinateSystemPosition(new Vector2(rect.x, rect.y + rect.height), texSize, area);
            GL.Vertex3(p1.x, p1.y, this.transform.position.z);
            GL.Vertex3(p2.x, p2.y, this.transform.position.z);
            GL.Vertex3(p3.x, p3.y, this.transform.position.z);
            GL.Vertex3(p4.x, p4.y, this.transform.position.z);
            GL.Vertex3(p1.x, p1.y, this.transform.position.z);
            GL.End();
        }
        GL.PopMatrix();
    }
Exemple #2
0
    public void OnRenderObject()
    {
        if (textureHolder.GetTexture() == null)
        {
            return;
        }
        var texSize = new Vector2(textureHolder.GetTexture().width, textureHolder.GetTexture().height);

        var contours = finder.Contours;
        var area     = EMath.GetShrinkFitSize(texSize, screenSize);

        GL.PushMatrix();
        GL.MultMatrix(transform.localToWorldMatrix);

        material.SetPass(0);
        foreach (var contour in contours)
        {
            GL.Begin(GL.LINE_STRIP);
            GL.Color(color);
            var points = OpenCVUtils.MatOfPointToVector2List(contour);
            //OpenCVUtils.RemoveNearPoint(points, nearPointThreshold);
            Vector3 startPoint = Vector3.zero;
            for (var i = 0; i < points.Count; i++)
            {
                var pos = OpenCVUtils.GetUnityCoordinateSystemPosition(points[i], texSize, area);
                var p   = new Vector3(pos.x, pos.y, this.transform.position.z);
                GL.Vertex(p);
                if (i == 0)
                {
                    startPoint = p;
                }
            }
            GL.Vertex(startPoint);
            GL.End();
        }
        GL.PopMatrix();
    }