diff --git a/App_Code/CommonUse.cs b/App_Code/CommonUse.cs
index 9320b94..12813ab 100644
--- a/App_Code/CommonUse.cs
+++ b/App_Code/CommonUse.cs
@@ -166,10 +166,9 @@ public class CommonUse
///
///
///
- public Mat GetPostionXYByFindPostionAndXieLv(Mat color_mat, VectorOfVectorOfPoint selected_contours, string postionCut, out string PYPostion, Image currentFrame, out double xielv)
+ public Mat GetPostionXYByFindPostionAndXieLv(Mat color_mat, VectorOfVectorOfPoint selected_contours, string postionCut, out string PYPostion, Image currentFrame, out double xielv, out string message)
{
-
-
+ message = string.Empty;
CommonUse commonUse = new CommonUse();
string[] postionc = postionCut.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries);
PYPostion = "";
@@ -179,6 +178,7 @@ public class CommonUse
int Y2 = 0, Y1 = 0, X2 = 0, X1 = 0;
+ xielv = -100;
for (int i = 0; i < postionc.Length; i++)
{
string[] postCutList = postionc[i].Split(',');
@@ -193,21 +193,27 @@ public class CommonUse
string mx = "";
try
{
- mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY);
+ mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY, out message);
}
catch
{
+ message = GetPostionString(i)+"未找到定位点";
xielv = -100;
return null;
- mx = "null";
- GrXY = new Point(0, 0);
}
if (mx.Trim() != "A")
{
+ message = GetPostionString(i) + "未找到定位点";
xielv = -100;
return null;
- break;
+ }
+
+ if (!string.IsNullOrWhiteSpace(message))
+ {
+ var posStr = GetPostionString(i);
+ message = posStr + "识别到多个定位点";
+ return null;
}
Point Mx = GrXY;
if (i == 0)//左上角
@@ -243,6 +249,19 @@ public class CommonUse
}
+ private string GetPostionString(int i)
+ {
+ switch (i)
+ {
+ case 0: return "左上角";
+ case 1: return "右上角";
+ case 2: return "左下角";
+ case 3: return "右下角";
+ default:
+ return "未知位置";
+ }
+ }
+
///
/// 将给定点集顺时针排序
///
@@ -535,8 +554,9 @@ 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)
+ int y_begin, int y_interval, int y_num, out Point gravityXY, out string messag)
{
+ messag = string.Empty;
int[] result = new int[x_num];//结果数组
//数组初值默认为-1
for (int i = 0; i < x_num; i++)
@@ -561,9 +581,10 @@ public class CommonUse
if (result[x_id] != -1)
{
- string str = string.Format("第{0}列存在多个答案!请擦拭干净后再扫描", x_id);
- result[x_id] = Convert.ToInt32(result[x_id].ToString() + value.ToString());
- gravityXY = gravity[i];
+ messag = "识别到多个定位点";
+ //string str = string.Format("第{0}列存在多个答案!请擦拭干净后再扫描", x_id);
+ //result[x_id] = Convert.ToInt32(result[x_id].ToString() + value.ToString());
+ //gravityXY = gravity[i];
}
else
@@ -574,8 +595,25 @@ public class CommonUse
gravityXY = gravity[i];
gravityXY.X = rect.X;
gravityXY.Y = rect.Y;
- break;
}
+
+ //if (result[x_id] != -1)
+ //{
+ // string str = string.Format("第{0}列存在多个答案!请擦拭干净后再扫描", x_id);
+ // result[x_id] = Convert.ToInt32(result[x_id].ToString() + value.ToString());
+ // gravityXY = gravity[i];
+
+ //}
+ //else
+ //{
+ // Rectangle rect = CvInvoke.BoundingRectangle(contour);
+ // //这里有修改
+ // result[x_id] = value;
+ // gravityXY = gravity[i];
+ // gravityXY.X = rect.X;
+ // gravityXY.Y = rect.Y;
+ // break;
+ //}
}
return result;
}
@@ -1010,11 +1048,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)
+ 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)
{
//画网格
Point pFind;
- int[] intArray = GetTargetGravityFind(contours, x_begin, x_interval, x_num, y_begin, y_interval, y_num, out pFind);
+ int[] intArray = GetTargetGravityFind(contours, x_begin, x_interval, x_num, y_begin, y_interval, y_num, out pFind, out message);
int maxValue = GetMaxValueOfArray(intArray);//数组最大值
pFindX = pFind;
string str = "";
diff --git a/Temp/Default.aspx.cs b/Temp/Default.aspx.cs
index 63a077d..c49a03a 100644
--- a/Temp/Default.aspx.cs
+++ b/Temp/Default.aspx.cs
@@ -364,11 +364,11 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
//Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
//VectorOfVectorOfPoint selected_contours1;
//selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);
-
- Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(currentFramext.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
+ string message = string.Empty;
+ Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(currentFramext.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv,out message);
if (xielv == -100)
{
- Response.Write("模板配置错误,斜率无法计算");
+ Response.Write(message);
return false;
}
int oldWidth = color_mxxx.Bitmap.Width;
diff --git a/Temp/TempDraw.aspx.cs b/Temp/TempDraw.aspx.cs
index 08174df..4316fc9 100644
--- a/Temp/TempDraw.aspx.cs
+++ b/Temp/TempDraw.aspx.cs
@@ -679,7 +679,8 @@ public class MK_Operater
string mx = "";
try
{
- mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY);
+ string message = string.Empty;
+ mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY,out message);
}
catch
{
@@ -747,7 +748,8 @@ public class MK_Operater
string mx = "";
try
{
- mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY);
+ string message = string.Empty;
+ mx = commonUse.GetValueAndDrawGrid_Find(color_mat.Bitmap, selected_contours, X, W, 1, Y, H, 1, "", out GrXY,out message);
}
catch
{
diff --git a/Temp/UserTemp.aspx.cs b/Temp/UserTemp.aspx.cs
index 85ec8df..1c65c30 100644
--- a/Temp/UserTemp.aspx.cs
+++ b/Temp/UserTemp.aspx.cs
@@ -189,11 +189,11 @@ public partial class Temp_UserTemp : System.Web.UI.Page
//Mat color_mat1 = commonUse.DrawContours(currentFramext.Mat, selected_contours1);
//commonUse.ShowMatWaitKey("shijuan bianjie", color_mat1, 0.6);
-
- Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(imagex.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
+ string message = string.Empty;
+ Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(imagex.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv,out message);
if (xielv == -100)
{
- Response.Write("TEMPERRO");
+ Response.Write(message);
return;
}
imagex.Dispose();