//using o0.Geometry; //using OpenCVForUnity.CoreModule; //using OpenCVForUnity.ImgcodecsModule; //using OpenCVForUnity.ImgprocModule; //using OpenCVForUnity.UnityUtils; //using System; //using System.Collections.Generic; //using UnityEngine; //namespace o0.Project //{ // public static partial class Extension // { // public static Texture cvLine(this Texture2D texture, List<(float Ax, float Ay, float Bx, float By)> lines) // { // Utils.setDebugMode(true); // Mat src = new Mat(texture.height, texture.width, CvType.CV_8UC4); // Utils.texture2DToMat(texture, src); // // 保留红通道 // Mat red = new Mat(); // Core.extractChannel(src, red, 0); // foreach (var i in lines) // Imgproc.line(src, new Point(i.Ax, i.Ay), new Point(i.Bx, i.By), new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA); // Texture2D cvLines = new Texture2D(src.cols(), src.rows(), TextureFormat.RGBA32, false); // Utils.matToTexture2D(src, cvLines); // Utils.setDebugMode(false); // return cvLines; // } // public static Texture2D cvHoughLinesP(this Texture2D texture, double rho = 1, double theta = Math.PI / 180, int threshold = 30, double minLineLength = 100, double maxLineGap = 10) // { // Utils.setDebugMode(true); // Mat src = new Mat(texture.height, texture.width, CvType.CV_8UC4); // Utils.texture2DToMat(texture, src); // // 保留红通道 // Mat red = new Mat(); // Core.extractChannel(src, red, 0); // //Imgcodecs.imwrite("output/red_opencv.jpg", red); // //Mat gray = new Mat(src.size(), src.type()); // //Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY); // Mat lines = new Mat(); // Imgproc.HoughLinesP(red, lines, rho, theta, threshold, minLineLength, maxLineGap); // //var LinesToSort = new List>(); // for (int i = 0; i < lines.rows(); i++) // { // var line = new int[4]; // lines.get(i, 0, line);//将线对应的极点坐标存到line数组中 // //LinesToSort.Add(new Line(new Vector(line[0], line[1]), new Vector(line[2], line[3]))); // Imgproc.line(src, new Point(line[0], line[1]), new Point(line[2], line[3]), new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA); // //Debug.Log("线段" + i + ": " + new Point(line[0], line[1]) + ", " + new Point(line[2], line[3])); // } // //LinesToSort.Sort((a,b)=>a.Length.CompareTo(-b.Length)); // // 取长度前4的线段 // //for (int i = 0; i < 4; i++) // //{ // // var l = LinesToSort[i]; // // Imgproc.line(src, new Point(l.A.x, l.A.y), new Point(l.B.x, l.B.y), new Scalar(255, 255, 255, 255), 2, Imgproc.LINE_AA); // //} // Texture2D cvLines = new Texture2D(src.cols(), src.rows(), TextureFormat.RGBA32, false); // Utils.matToTexture2D(src, cvLines); // Utils.setDebugMode(false); // return cvLines; // } // } //}