using OpenCvSharp; namespace BetterGenshinImpact.Core.Recognition.OpenCv; public class ArithmeticHelper { /// /// 水平投影 /// /// /// public static int[] HorizontalProjection(Mat gray) { var projection = new int[gray.Height]; //对每一行计算投影值 for (var y = 0; y < gray.Height; ++y) //遍历这一行的每一个像素,如果是有效的,累加投影值 for (var x = 0; x < gray.Width; ++x) { var s = gray.Get(y, x); if (s.Item0 == 255) projection[y]++; } return projection; } /// /// 垂直投影 /// /// /// public static int[] VerticalProjection(Mat gray) { var projection = new int[gray.Width]; //遍历每一列计算投影值 for (var x = 0; x < gray.Width; ++x) for (var y = 0; y < gray.Height; ++y) { var s = gray.Get(y, x); if (s.Item0 == 255) projection[x]++; } return projection; } }