定位点识别优化提示
This commit is contained in:
parent
8af8953771
commit
46d928936e
|
|
@ -166,10 +166,9 @@ public class CommonUse
|
||||||
/// <param name="width"></param>
|
/// <param name="width"></param>
|
||||||
/// <param name="height"></param>
|
/// <param name="height"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Mat GetPostionXYByFindPostionAndXieLv(Mat color_mat, VectorOfVectorOfPoint selected_contours, string postionCut, out string PYPostion, Image<Gray, byte> currentFrame, out double xielv)
|
public Mat GetPostionXYByFindPostionAndXieLv(Mat color_mat, VectorOfVectorOfPoint selected_contours, string postionCut, out string PYPostion, Image<Gray, byte> currentFrame, out double xielv, out string message)
|
||||||
{
|
{
|
||||||
|
message = string.Empty;
|
||||||
|
|
||||||
CommonUse commonUse = new CommonUse();
|
CommonUse commonUse = new CommonUse();
|
||||||
string[] postionc = postionCut.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries);
|
string[] postionc = postionCut.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
PYPostion = "";
|
PYPostion = "";
|
||||||
|
|
@ -179,6 +178,7 @@ public class CommonUse
|
||||||
|
|
||||||
int Y2 = 0, Y1 = 0, X2 = 0, X1 = 0;
|
int Y2 = 0, Y1 = 0, X2 = 0, X1 = 0;
|
||||||
|
|
||||||
|
xielv = -100;
|
||||||
for (int i = 0; i < postionc.Length; i++)
|
for (int i = 0; i < postionc.Length; i++)
|
||||||
{
|
{
|
||||||
string[] postCutList = postionc[i].Split(',');
|
string[] postCutList = postionc[i].Split(',');
|
||||||
|
|
@ -193,21 +193,27 @@ public class CommonUse
|
||||||
string mx = "";
|
string mx = "";
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
message = GetPostionString(i)+"未找到定位点";
|
||||||
xielv = -100;
|
xielv = -100;
|
||||||
return null;
|
return null;
|
||||||
mx = "null";
|
|
||||||
GrXY = new Point(0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mx.Trim() != "A")
|
if (mx.Trim() != "A")
|
||||||
{
|
{
|
||||||
|
message = GetPostionString(i) + "未找到定位点";
|
||||||
xielv = -100;
|
xielv = -100;
|
||||||
return null;
|
return null;
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(message))
|
||||||
|
{
|
||||||
|
var posStr = GetPostionString(i);
|
||||||
|
message = posStr + "识别到多个定位点";
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
Point Mx = GrXY;
|
Point Mx = GrXY;
|
||||||
if (i == 0)//左上角
|
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 "未知位置";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将给定点集顺时针排序
|
/// 将给定点集顺时针排序
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -535,8 +554,9 @@ 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)
|
int y_begin, int y_interval, int y_num, out Point gravityXY, out string messag)
|
||||||
{
|
{
|
||||||
|
messag = string.Empty;
|
||||||
int[] result = new int[x_num];//结果数组
|
int[] result = new int[x_num];//结果数组
|
||||||
//数组初值默认为-1
|
//数组初值默认为-1
|
||||||
for (int i = 0; i < x_num; i++)
|
for (int i = 0; i < x_num; i++)
|
||||||
|
|
@ -561,9 +581,10 @@ public class CommonUse
|
||||||
|
|
||||||
if (result[x_id] != -1)
|
if (result[x_id] != -1)
|
||||||
{
|
{
|
||||||
string str = string.Format("第{0}列存在多个答案!请擦拭干净后再扫描", x_id);
|
messag = "识别到多个定位点";
|
||||||
result[x_id] = Convert.ToInt32(result[x_id].ToString() + value.ToString());
|
//string str = string.Format("第{0}列存在多个答案!请擦拭干净后再扫描", x_id);
|
||||||
gravityXY = gravity[i];
|
//result[x_id] = Convert.ToInt32(result[x_id].ToString() + value.ToString());
|
||||||
|
//gravityXY = gravity[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -574,8 +595,25 @@ 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;
|
||||||
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -1010,11 +1048,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)
|
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;
|
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);//数组最大值
|
int maxValue = GetMaxValueOfArray(intArray);//数组最大值
|
||||||
pFindX = pFind;
|
pFindX = pFind;
|
||||||
string str = "";
|
string str = "";
|
||||||
|
|
|
||||||
|
|
@ -364,11 +364,11 @@ public partial class 外部答题卡_Default : System.Web.UI.Page
|
||||||
//Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
|
//Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
|
||||||
//VectorOfVectorOfPoint selected_contours1;
|
//VectorOfVectorOfPoint selected_contours1;
|
||||||
//selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);
|
//selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);
|
||||||
|
string message = string.Empty;
|
||||||
Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(currentFramext.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
|
Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(currentFramext.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv,out message);
|
||||||
if (xielv == -100)
|
if (xielv == -100)
|
||||||
{
|
{
|
||||||
Response.Write("模板配置错误,斜率无法计算");
|
Response.Write(message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int oldWidth = color_mxxx.Bitmap.Width;
|
int oldWidth = color_mxxx.Bitmap.Width;
|
||||||
|
|
|
||||||
|
|
@ -679,7 +679,8 @@ public class MK_Operater
|
||||||
string mx = "";
|
string mx = "";
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
|
@ -747,7 +748,8 @@ public class MK_Operater
|
||||||
string mx = "";
|
string mx = "";
|
||||||
try
|
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
|
catch
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -189,11 +189,11 @@ public partial class Temp_UserTemp : System.Web.UI.Page
|
||||||
//Mat color_mat1 = commonUse.DrawContours(currentFramext.Mat, selected_contours1);
|
//Mat color_mat1 = commonUse.DrawContours(currentFramext.Mat, selected_contours1);
|
||||||
|
|
||||||
//commonUse.ShowMatWaitKey("shijuan bianjie", color_mat1, 0.6);
|
//commonUse.ShowMatWaitKey("shijuan bianjie", color_mat1, 0.6);
|
||||||
|
string message = string.Empty;
|
||||||
Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(imagex.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv);
|
Mat color_mxxx = commonUse.GetPostionXYByFindPostionAndXieLv(imagex.Mat, selected_contours1, GetData[0], out PYPostionList, currentFramext, out xielv,out message);
|
||||||
if (xielv == -100)
|
if (xielv == -100)
|
||||||
{
|
{
|
||||||
Response.Write("TEMPERRO");
|
Response.Write(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
imagex.Dispose();
|
imagex.Dispose();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue