定位点切割增加右上角定位点的宽度

This commit is contained in:
强 杨 2024-01-10 10:48:19 +08:00
parent d34e26d6fc
commit 17bf9bc281
3 changed files with 23 additions and 12 deletions

View File

@ -191,9 +191,11 @@ public class CommonUse
//ShowMatWaitKey("123", aaa, 0.8); //ShowMatWaitKey("123", aaa, 0.8);
string mx = ""; string mx = "";
Rectangle rt = new Rectangle();
try 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 catch
{ {
@ -224,7 +226,7 @@ public class CommonUse
} }
if (i == 1)//右上角 if (i == 1)//右上角
{ {
PostionWW = GrXY.X; PostionWW = GrXY.X + rt.Width;
} }
if (i == 2)//左下角 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 / 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 = ((rect.Width > 3 && rect.Height > 2) && (area > 80 && area <= 15000));
//bool bo = pxNums > 130 && pxNums < 300; //bool bo = pxNums > 130 && pxNums < 300;
bool bo = (CvInvoke.IsContourConvex(approx_curve) bool bo = (CvInvoke.IsContourConvex(approx_curve)
&& (rect.Width > 10 && rect.Height > 10) && (rect.Width > 10 && rect.Height > 10)
&& (area > 200 && area < 2000) && (area > 200 && area < 2000)
&& (rect.Width < 50 && rect.Height < 50) && (rect.Width < 50 && rect.Height < 50)
&& pxNums > 200); && pxNums > 200);
if (bo) if (bo)
{ {
@ -560,7 +562,7 @@ public class CommonUse
/// <param name="y_num"></param> /// <param name="y_num"></param>
/// <returns></returns> /// <returns></returns>
public int[] GetTargetGravityFind(VectorOfVectorOfPoint contours, int x_begin, int x_interval, int x_num, 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; messag = string.Empty;
int[] result = new int[x_num];//结果数组 int[] result = new int[x_num];//结果数组
@ -575,6 +577,7 @@ public class CommonUse
Point[] gravity = GetGravityOfContours(contours);//轮廓中心点坐标 Point[] gravity = GetGravityOfContours(contours);//轮廓中心点坐标
gravityXY = new Point(0, 0); gravityXY = new Point(0, 0);
rectDT = new Rectangle(0, 0, 0, 0);
for (int i = 0; i < contours.Size; i++) for (int i = 0; i < contours.Size; i++)
{ {
VectorOfPoint contour = contours[i]; VectorOfPoint contour = contours[i];
@ -601,6 +604,7 @@ public class CommonUse
gravityXY = gravity[i]; gravityXY = gravity[i];
gravityXY.X = rect.X; gravityXY.X = rect.X;
gravityXY.Y = rect.Y; gravityXY.Y = rect.Y;
rectDT = rect;
} }
//if (result[x_id] != -1) //if (result[x_id] != -1)
@ -1054,11 +1058,11 @@ public class CommonUse
/// <param name="strText">输出文字</param> /// <param name="strText">输出文字</param>
/// <returns></returns> /// <returns></returns>
public string GetValueAndDrawGrid_Find(Bitmap img, VectorOfVectorOfPoint contours, 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; 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);//数组最大值 int maxValue = GetMaxValueOfArray(intArray);//数组最大值
pFindX = pFind; pFindX = pFind;
string str = ""; string str = "";

View File

@ -23,6 +23,7 @@ using Emgu.CV.Flann;
using System.Data.SqlTypes; using System.Data.SqlTypes;
using System.Security.AccessControl; using System.Security.AccessControl;
using System.IO; using System.IO;
using System.Text.RegularExpressions;
public partial class _Default : System.Web.UI.Page 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 wL = Convert.ToInt32(W / xuanXiang);
int hL = Convert.ToInt32(H / tiliang); int hL = Convert.ToInt32(H / tiliang);
Image<Gray, byte> bytimg = GetMatCutImg(color_mat.Bitmap, X, Y, W, H); Image<Gray, byte> 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; X = 0; Y = 0;
Mat src = bytimg.Mat; Mat src = bytimg.Mat;

View File

@ -677,10 +677,11 @@ public class MK_Operater
int H = Convert.ToInt32(Convert.ToDouble(postCutList[3])); int H = Convert.ToInt32(Convert.ToDouble(postCutList[3]));
//commonUse.DrawGridByXY(测试查找坐标.myFrom.PB_guodu, X, W, 1, Y, H, 1);Response.Write(ImgToBase64String(bmp)); //commonUse.DrawGridByXY(测试查找坐标.myFrom.PB_guodu, X, W, 1, Y, H, 1);Response.Write(ImgToBase64String(bmp));
string mx = ""; string mx = "";
Rectangle rt = new Rectangle();
try try
{ {
string message = string.Empty; 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 catch
{ {
@ -746,10 +747,11 @@ public class MK_Operater
int W = Convert.ToInt32(Convert.ToDouble(postCutList[2])); int W = Convert.ToInt32(Convert.ToDouble(postCutList[2]));
int H = Convert.ToInt32(Convert.ToDouble(postCutList[3])); int H = Convert.ToInt32(Convert.ToDouble(postCutList[3]));
string mx = ""; string mx = "";
Rectangle rt = new Rectangle();
try try
{ {
string message = string.Empty; 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 catch
{ {
@ -771,7 +773,7 @@ public class MK_Operater
} }
if (i == 1)//右上角 if (i == 1)//右上角
{ {
PostionWW = GrXY.X; PostionWW = GrXY.X+ rt.Width;
} }
if (i == 2)//左下角 if (i == 2)//左下角
{ {