From 17bf9bc281833c920ba9e836a213d099e6ab6f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=BA=20=E6=9D=A8?= Date: Wed, 10 Jan 2024 10:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=BD=8D=E7=82=B9=E5=88=87=E5=89=B2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=B3=E4=B8=8A=E8=A7=92=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App_Code/CommonUse.cs | 22 +++++++++++++--------- Temp/Default.aspx.cs | 5 +++++ Temp/TempDraw.aspx.cs | 8 +++++--- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/App_Code/CommonUse.cs b/App_Code/CommonUse.cs index 8390abb..77f204a 100644 --- a/App_Code/CommonUse.cs +++ b/App_Code/CommonUse.cs @@ -191,9 +191,11 @@ public class CommonUse //ShowMatWaitKey("123", aaa, 0.8); string mx = ""; + Rectangle rt = new Rectangle(); try { - mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY, out message); + + mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY, out message, out rt); } catch { @@ -224,7 +226,7 @@ public class CommonUse } if (i == 1)//右上角 { - PostionWW = GrXY.X; + PostionWW = GrXY.X + rt.Width; } if (i == 2)//左下角 { @@ -446,10 +448,10 @@ public class CommonUse // bool bo = (rect.Width / rect.Height >= ratio && (rect.Width > 3 && rect.Height > 2) && (area > 200 && area <= 4500)); //bool bo = ((rect.Width > 3 && rect.Height > 2) && (area > 80 && area <= 15000)); //bool bo = pxNums > 130 && pxNums < 300; - bool bo = (CvInvoke.IsContourConvex(approx_curve) - && (rect.Width > 10 && rect.Height > 10) - && (area > 200 && area < 2000) - && (rect.Width < 50 && rect.Height < 50) + bool bo = (CvInvoke.IsContourConvex(approx_curve) + && (rect.Width > 10 && rect.Height > 10) + && (area > 200 && area < 2000) + && (rect.Width < 50 && rect.Height < 50) && pxNums > 200); if (bo) { @@ -560,7 +562,7 @@ public class CommonUse /// /// public int[] GetTargetGravityFind(VectorOfVectorOfPoint contours, int x_begin, int x_interval, int x_num, - int y_begin, int y_interval, int y_num, out Point gravityXY, out string messag) + int y_begin, int y_interval, int y_num, out Point gravityXY, out string messag, out Rectangle rectDT) { messag = string.Empty; int[] result = new int[x_num];//结果数组 @@ -575,6 +577,7 @@ public class CommonUse Point[] gravity = GetGravityOfContours(contours);//轮廓中心点坐标 gravityXY = new Point(0, 0); + rectDT = new Rectangle(0, 0, 0, 0); for (int i = 0; i < contours.Size; i++) { VectorOfPoint contour = contours[i]; @@ -601,6 +604,7 @@ public class CommonUse gravityXY = gravity[i]; gravityXY.X = rect.X; gravityXY.Y = rect.Y; + rectDT = rect; } //if (result[x_id] != -1) @@ -1054,11 +1058,11 @@ public class CommonUse /// 输出文字 /// public string GetValueAndDrawGrid_Find(Bitmap img, VectorOfVectorOfPoint contours, - int x_begin, int x_interval, int x_num, int y_begin, int y_interval, int y_num, string strText, out Point pFindX, out string message) + int x_begin, int x_interval, int x_num, int y_begin, int y_interval, int y_num, string strText, out Point pFindX, out string message, out Rectangle rt) { //画网格 Point pFind; - int[] intArray = GetTargetGravityFind(contours, x_begin, x_interval, x_num, y_begin, y_interval, y_num, out pFind, out message); + int[] intArray = GetTargetGravityFind(contours, x_begin, x_interval, x_num, y_begin, y_interval, y_num, out pFind, out message, out rt); int maxValue = GetMaxValueOfArray(intArray);//数组最大值 pFindX = pFind; string str = ""; diff --git a/Temp/Default.aspx.cs b/Temp/Default.aspx.cs index e491a65..e6f6d85 100644 --- a/Temp/Default.aspx.cs +++ b/Temp/Default.aspx.cs @@ -23,6 +23,7 @@ using Emgu.CV.Flann; using System.Data.SqlTypes; using System.Security.AccessControl; using System.IO; +using System.Text.RegularExpressions; public partial class 外部答题卡_Default : System.Web.UI.Page { @@ -514,7 +515,11 @@ public partial class 外部答题卡_Default : System.Web.UI.Page int wL = Convert.ToInt32(W / xuanXiang); int hL = Convert.ToInt32(H / tiliang); + Image bytimg = GetMatCutImg(color_mat.Bitmap, X, Y, W, H); + //Bitmap bmp = ScaleToSize(tempImage.Bitmap, tempImage.Bitmap.Width * 4, tempImage.Bitmap.Height * 4, groupNo); + + X = 0; Y = 0; Mat src = bytimg.Mat; diff --git a/Temp/TempDraw.aspx.cs b/Temp/TempDraw.aspx.cs index 4316fc9..a146def 100644 --- a/Temp/TempDraw.aspx.cs +++ b/Temp/TempDraw.aspx.cs @@ -677,10 +677,11 @@ public class MK_Operater int H = Convert.ToInt32(Convert.ToDouble(postCutList[3])); //commonUse.DrawGridByXY(测试查找坐标.myFrom.PB_guodu, X, W, 1, Y, H, 1);Response.Write(ImgToBase64String(bmp)); string mx = ""; + Rectangle rt = new Rectangle(); try { string message = string.Empty; - mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY,out message); + mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY,out message ,out rt); } catch { @@ -746,10 +747,11 @@ public class MK_Operater int W = Convert.ToInt32(Convert.ToDouble(postCutList[2])); int H = Convert.ToInt32(Convert.ToDouble(postCutList[3])); string mx = ""; + Rectangle rt = new Rectangle(); try { string message = string.Empty; - mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY,out message); + mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY,out message ,out rt); } catch { @@ -771,7 +773,7 @@ public class MK_Operater } if (i == 1)//右上角 { - PostionWW = GrXY.X; + PostionWW = GrXY.X+ rt.Width; } if (i == 2)//左下角 {