public string ToGrayAndOCR(Mat mat) { var graphicsTools = GraphicsTools.GetInstance(); var gray = graphicsTools.ToGray(mat); return(OCR(mat)); }
/// <summary> /// /// </summary> /// <param name="capture">完整的截图捕获</param> /// <param name="captureRect">完整的截图所对应的矩形 相对于屏幕</param> /// <param name="rectRate">子矩形的比率 相对于capture</param> /// <returns></returns> public Mat GetCaptureRect(Mat mat, RECT captureRect, Vec4f rectRate) { var relativeRect = captureRect.GetChildRectByRate(rectRate); var childMat = GraphicsTools.GetInstance().GetChildMatByRECT(mat, relativeRect); return(childMat); }
public Bitmap DoCapture(RECT rect) { var capture = Tools.GetInstance().CaptureWindow(rect); GraphicsTools.GetInstance().DisplayImage("DoCapture", capture); return(capture); }
public static GraphicsTools GetInstance() { if (instance == null) { instance = new GraphicsTools(); } return(instance); }
public string ToBinAndOCR(Mat mat, int threshold) { var graphicsTools = GraphicsTools.GetInstance(); var gray = graphicsTools.ToGray(mat); var bin = graphicsTools.ToBinary(gray, threshold); return(OCR(bin.ToRawBitmap())); }
public static Mat GetChildMatByRectRate(this Mat mat, Vec4f rectRate) { var rect = new RECT() { x1 = 0, y1 = 0, x2 = mat.Width, y2 = mat.Height }; var relativeRect = rect.GetChildRectByRate(rectRate); var childMat = GraphicsTools.GetInstance().GetChildMatByRECT(mat, relativeRect); return(childMat); }
public void GetViewportTopBottomBounds(Bitmap bitmap) { var graphicsTools = GraphicsTools.GetInstance(); var mat = bitmap.ToOpenCvMat(); var bin = graphicsTools.ToGrayBinary(mat, 50); var width = bitmap.Width; if (configMgr.FixedViewportTopBottomY) { TopY = configMgr.FixedViewportTopY; BottomY = configMgr.FixedViewportBottomY; } else { var threshold = (int)(255 * bin.Rows * 0.5); var preSum = 0; for (int r = 0; r < bin.Rows; r++) { var sum = 0; for (int c = 0; c < bin.Cols; c++) { var clr = bin.GetPixel(r, c); sum += clr.R; } var diff = Math.Abs(sum - preSum); if (diff > threshold) { TopY = r; break; } preSum = sum; } preSum = 0; for (int r = bin.Rows - 1; r >= 0; r--) { var sum = 0; for (int c = 0; c < bin.Cols; c++) { var clr = bin.GetPixel(r, c); sum += clr.R; } var diff = Math.Abs(sum - preSum); if (diff > threshold) { BottomY = r; break; } preSum = sum; } } if (checkTopBottomBounds) { var height = 1.0 * width * this.height / this.width; var validTopY = 36; var validTopYOff = 10; var validBottomY = height + 36; var validBottomYOff = 10; var topYOff = Math.Abs(TopY - validTopY); if (topYOff > validTopYOff) { throw new NoTrackTraceException("无法检测到Mumu模拟器上边界"); } var bottomYOff = Math.Abs(BottomY - validBottomY); if (bottomYOff > validBottomYOff) { throw new NoTrackTraceException("无法检测到Mumu模拟器下边界"); } } }