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; }
public void Save() { var piList = new List <CorrectableQuad.PointInfomation>(); for (var i = 0; i < Points.Length; i++) { var p = Points[i]; var uv = new Vector2( EMath.Map(p.x, -aspect.x / 2f, aspect.x / 2f, 0, 1), EMath.Map(p.y, -aspect.y / 2f, aspect.y / 2f, 0, 1) ); var pi = new CorrectableQuad.PointInfomation { position = p, uv = uv }; piList.Add(pi); print(i + " : " + uv); } var setting = new QuadCorrectionSetting(); setting.LeftTop = new CorrectableQuad.JPointInfomation(piList[0]); setting.RightTop = new CorrectableQuad.JPointInfomation(piList[1]); setting.RightBottom = new CorrectableQuad.JPointInfomation(piList[2]); setting.LeftBottom = new CorrectableQuad.JPointInfomation(piList[3]); CorrectEvent?.Invoke(setting); IOHandler.SaveJson(IOHandler.IntoStreamingAssets(settingFileName), setting); }
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(); }
protected Function(EMath <T> math, params Expression <T>[] args) : base(math) { Arguments = args; try { } catch (Exception e) { Console.WriteLine(e); throw; } }
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 CalcCircumCenter() { float a, b, c; LineFromPoints(A, B, out a, out b, out c); float e, f, g; LineFromPoints(B, C, out e, out f, out g); PerpendicularBisectorFromLine(A, B, ref a, ref b, ref c); PerpendicularBisectorFromLine(B, C, ref e, ref f, ref g); CirC = lineLineIntersection(a, b, c, e, f, g); CirR = EMath.Len(A, CirC); }
IEnumerator ProcessRoutine() { while (index < files.Count) { var bytes = File.ReadAllBytes(files[index]); index++; texture.LoadImage(bytes); texture.Apply(); renderer.transform.localPosition = Vector3.zero; renderer.material.mainTexture = texture; var size = EMath.GetNormalizedExpandAspect(new Vector2(texture.width, texture.height)); renderer.transform.localScale = new Vector3(size.x, size.y, 1f); localScale = renderer.transform.localScale; scaleRate = 1f; isWaiting = true; while (isWaiting) { yield return(null); } if (!isAllow) { continue; } captureCamera.Render(); yield return(null); TextureUtils.RenderTexture2Texture2D(rt, resultTexture); var resultBytes = resultTexture.EncodeToJPG(); var c = count; if (dictionary.ContainsKey(index)) { c = dictionary[index]; } else { count++; c = count; dictionary.Add(index, c); } var path = Path.Combine(saveDirectory, (offsetIndex + c) + ".jpg"); File.WriteAllBytes(path, resultBytes); var progress = ((float)index / files.Count); print(progress); yield return(null); } print("complete"); }
public void Generate() { var eps = Mapper.Map <ApertureSequence, ExitPupilSequence>(this); eps.Generate(); var epsHalf = eps.GetShallowCopy(); epsHalf.ApertureIn = EMath.RInt(epsHalf.ApertureIn / 2); epsHalf.Generate(); var epsDouble = eps.GetShallowCopy(); epsDouble.ApertureIn = EMath.RInt(epsDouble.ApertureIn * 2); epsDouble.Generate(); ExitPupilSequences.Clear(); ExitPupilSequences.Add(epsDouble); ExitPupilSequences.Add(eps); ExitPupilSequences.Add(epsHalf); }
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(); }
IEnumerator GenerateRoutine() { string[] files = Directory.GetFiles(loadDirectoryPath); files = files.Where(e => targetExtensions.Contains(Path.GetExtension(e))).ToArray(); for (var i = 0; i < files.Length; i++) { var bytes = File.ReadAllBytes(files[i]); baseTexture.LoadImage(bytes); baseTexture.Apply(); baseImageRenderer.material.mainTexture = baseTexture; var size = EMath.GetNormalizedExpandAspect(new Vector2(baseTexture.width, baseTexture.height)); baseImageRenderer.transform.localScale = new Vector3(size.x, size.y, 1f); clampCamera.Render(); yield return(null); //Aに画像をセット imageARenderer.material.mainTexture = clampedTexture; filterGroup.Filter(clampedTexture); yield return(null); var filteredTexture = filterGroup.GetTexture(); imageBRenderer.material.mainTexture = filteredTexture; resultCamera.Render(); yield return(null); TextureUtils.RenderTexture2Texture2D(resultRenderTexture, resultTexture); var resultBytes = resultTexture.EncodeToJPG(); var path = Path.Combine(saveDirectoryPath, (i + 1) + ".jpg"); File.WriteAllBytes(path, resultBytes); var progress = ((float)i / files.Length); EditorUtility.DisplayProgressBar("Processing", "processing...", progress); yield return(null); } EditorUtility.ClearProgressBar(); print("complete"); }
public ApertureSequence(EMath eMath) { EMath = eMath; Mapper.CreateMap <ApertureSequence, ExitPupilSequence>(); }
//画面上の位置を取得 //一気にUnity上の画面の位置に変換する public static Vector2 GetUnityCoordinateSystemPosition(Vector2 position, Vector2 area1, Vector2 area2) { return(new Vector2(EMath.Map(position.x, 0f, area1.x, -area2.x / 2f, area2.x / 2f), EMath.Map(position.y, 0f, area1.y, area2.y / 2f, -area2.y / 2f))); }
private void ResizeControl(ControlResizeParms crp, double widthRatio, double heightRatio) { crp.Control.Location = new Point(EMath.RInt(crp.Location.X * widthRatio), EMath.RInt(crp.Location.Y * heightRatio)); crp.Control.Size = new Size(EMath.RInt(crp.Size.Width * widthRatio), EMath.RInt(crp.Size.Height * heightRatio)); }
public ResizeComponentProportionalStrategy(EMath eMath) { EMath = eMath; ListControlResizeParms = new List <ControlResizeParms>(); }
//Unityの座標系に合わせて正規化された座標(-1~+1) public static Vector2 GetUnityCoordinateSystemNormalizedPosition(Vector2 position, Vector2 textureSize) { return(new Vector2(EMath.Map(position.x, 0f, textureSize.x, -1f, 1f), EMath.Map(position.y, 0f, textureSize.y, 1f, -1f))); }
public Expression(EMath <T> math) { Math = math; }