o0OpenCV.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //using o0.Geometry;
  2. //using OpenCVForUnity.CoreModule;
  3. //using OpenCVForUnity.ImgcodecsModule;
  4. //using OpenCVForUnity.ImgprocModule;
  5. //using OpenCVForUnity.UnityUtils;
  6. //using System;
  7. //using System.Collections.Generic;
  8. //using UnityEngine;
  9. //namespace o0.Project
  10. //{
  11. // public static partial class Extension
  12. // {
  13. // public static Texture cvLine(this Texture2D texture, List<(float Ax, float Ay, float Bx, float By)> lines)
  14. // {
  15. // Utils.setDebugMode(true);
  16. // Mat src = new Mat(texture.height, texture.width, CvType.CV_8UC4);
  17. // Utils.texture2DToMat(texture, src);
  18. // // 保留红通道
  19. // Mat red = new Mat();
  20. // Core.extractChannel(src, red, 0);
  21. // foreach (var i in lines)
  22. // 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);
  23. // Texture2D cvLines = new Texture2D(src.cols(), src.rows(), TextureFormat.RGBA32, false);
  24. // Utils.matToTexture2D(src, cvLines);
  25. // Utils.setDebugMode(false);
  26. // return cvLines;
  27. // }
  28. // public static Texture2D cvHoughLinesP(this Texture2D texture, double rho = 1, double theta = Math.PI / 180, int threshold = 30, double minLineLength = 100, double maxLineGap = 10)
  29. // {
  30. // Utils.setDebugMode(true);
  31. // Mat src = new Mat(texture.height, texture.width, CvType.CV_8UC4);
  32. // Utils.texture2DToMat(texture, src);
  33. // // 保留红通道
  34. // Mat red = new Mat();
  35. // Core.extractChannel(src, red, 0);
  36. // //Imgcodecs.imwrite("output/red_opencv.jpg", red);
  37. // //Mat gray = new Mat(src.size(), src.type());
  38. // //Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
  39. // Mat lines = new Mat();
  40. // Imgproc.HoughLinesP(red, lines, rho, theta, threshold, minLineLength, maxLineGap);
  41. // //var LinesToSort = new List<Line<float>>();
  42. // for (int i = 0; i < lines.rows(); i++)
  43. // {
  44. // var line = new int[4];
  45. // lines.get(i, 0, line);//将线对应的极点坐标存到line数组中
  46. // //LinesToSort.Add(new Line<float>(new Vector<float>(line[0], line[1]), new Vector<float>(line[2], line[3])));
  47. // 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);
  48. // //Debug.Log("线段" + i + ": " + new Point(line[0], line[1]) + ", " + new Point(line[2], line[3]));
  49. // }
  50. // //LinesToSort.Sort((a,b)=>a.Length.CompareTo(-b.Length));
  51. // // 取长度前4的线段
  52. // //for (int i = 0; i < 4; i++)
  53. // //{
  54. // // var l = LinesToSort[i];
  55. // // 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);
  56. // //}
  57. // Texture2D cvLines = new Texture2D(src.cols(), src.rows(), TextureFormat.RGBA32, false);
  58. // Utils.matToTexture2D(src, cvLines);
  59. // Utils.setDebugMode(false);
  60. // return cvLines;
  61. // }
  62. // }
  63. //}