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(); }
void Start() { var resolution = EMath.GetShrinkFitSize(correctableQuadController.Size, Vector2.one * maxResolution); renderTexture = new RenderTexture((int)resolution.x, (int)resolution.y, 24, RenderTextureFormat.ARGB32); correctableQuadController.Cam.targetTexture = renderTexture; }
private void VideoCaptureController_ChangeTextureEvent(TextureHolderBase sender, Texture texture) { var frameSize = new Vector2(camera.orthographicSize * 2 * camera.aspect, camera.orthographicSize * 2); var size = EMath.GetShrinkFitSize(new Vector2(texture.width, texture.height), frameSize); this.transform.localScale = new Vector3(size.x, size.y, 1f); renderer.material.mainTexture = textureHolder.GetTexture(); }
public void Init(Vector2 size) { var h = captureCamera.orthographicSize * 2f; aspect = EMath.GetShrinkFitSize(size, new Vector2(h * captureCamera.aspect, h)); renderer.transform.localScale = new Vector3(aspect.x, aspect.y, 1f); InitPoints(); Restore(); }
private void Restore(QuadCorrectionSetting setting) { Size = fitToAngleOfView ? EMath.GetShrinkFitSize(this.destSize, new Vector2(cam.orthographicSize * 2f * cam.aspect, cam.orthographicSize * 2f)) : destSize; //print("size : " + Size); var lt = new Vector2(-Size.x / 2f, Size.y / 2f); var rt = new Vector2(Size.x / 2f, Size.y / 2f); var rb = new Vector2(Size.x / 2f, -Size.y / 2f); var lb = new Vector2(-Size.x / 2f, -Size.y / 2f); correctableQuad.Init(setting.LeftTop.ToPointInfomation(), setting.RightTop.ToPointInfomation(), setting.RightBottom.ToPointInfomation(), setting.LeftBottom.ToPointInfomation(), segmentX, segmentY ); correctableQuad.Refresh(lt, rt, rb, lb); }
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(); }