Commit c5ee0a04 刘韬

NS200贴标计算更新

1 个父辈 01437829
......@@ -12,224 +12,6 @@ namespace DeviceLibrary.AutoScanAndLabel
{
public static class LabelingPosition
{
//public static Point MultipleChoiceLabeling(LabelParam labelParam, Point centrality, out int angle,out Bitmap bitmaps)
//{
// //7寸XY偏移量
// int Xpianyilian_7 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_7", 0);
// int Ypianyilian_7 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_7", 0);
// //13寸XY偏移量
// int Xpianyilian_13 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_13", 0);
// int Ypianyilian_13 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_13", 0);
// //15寸XY偏移量
// int Xpianyilian_15 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_15", 0);
// int Ypianyilian_15 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_15", 0);
// //7寸朝那个方向贴标true顺时针,false逆时针
// bool istoward_7 = ConfigHelper.Config.Get<bool>("Labeling_istoward_7", true);
// int degree_7 = ConfigHelper.Config.Get<int>("Labeling_degree_7", 90);
// //13寸朝那个方向贴标true顺时针,false逆时针
// bool istoward_13 = ConfigHelper.Config.Get<bool>("Labeling_istoward_13", true);
// int degree_13 = ConfigHelper.Config.Get<int>("Labeling_degree_13", 90);
// //15寸朝那个方向贴标true顺时针,false逆时针
// bool istoward_15 = ConfigHelper.Config.Get<bool>("Labeling_istoward_15", true);
// int degree_15 = ConfigHelper.Config.Get<int>("Labeling_degree_15", 90);
// //7寸标签旋转多少度
// int Scalerotationdegree_7 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_7", 90);
// //13寸标签旋转多少度
// int Scalerotationdegree_13 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_13", 90);
// //15寸标签旋转多少度
// int Scalerotationdegree_15 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_15", 90);
// #region 数据
// //标签位置
// SolidBrush blue = new SolidBrush(Color.DarkBlue);
// //料盘中心点
// SolidBrush red = new SolidBrush(Color.Red);
// //贴标位置
// SolidBrush yeelow = new SolidBrush(Color.Yellow);
// Bitmap srcbitmap;
// if (File.Exists(labelParam.bitmapfilename))
// {
// srcbitmap = new Bitmap(labelParam.bitmapfilename);
// }
// else
// {
// srcbitmap = new Bitmap(3648, 3648);
// }
// Bitmap bitmap = new Bitmap(srcbitmap);
// Graphics g = Graphics.FromImage(bitmap);
// Size pointsize = new Size(60, 60);
// g.FillEllipse(red, new Rectangle(centrality, pointsize));
// int idenx = 0; //Array.FindIndex(labelParam.AMatch, x => x);
// if (idenx == -1)
// {
// idenx = 0;
// }
// int angles = (int)labelParam.codeInfos[idenx].Orientation;
// Point CalPoint = new Point(labelParam.codeInfos[idenx].X, labelParam.codeInfos[idenx].Y);
// g.FillEllipse(blue, new Rectangle(CalPoint, pointsize));
// #endregion
// LogNet.log.Info($"标签坐标x={CalPoint.X},y={CalPoint.Y},中心点x={centrality.X},y={centrality.Y}");
// Point point = new Point();
// switch (labelParam.PlateW)
// {
// case 13:
// point = LabelingAngle_13(CalPoint, centrality, out angle);
// break;
// case 15:
// point = LabelingAngle_15(CalPoint, centrality, out angle);
// break;
// default:
// point = LabelingAngle_7(CalPoint, centrality, out angle);
// break;
// }
// g.FillEllipse(yeelow, new Rectangle(point, pointsize));
// g.Save();
// g.Dispose();
// ImageSave(bitmap);
// bitmaps = bitmap;
// return point;
//}
public static Point MultipleChoiceLabeling_new(string pathfile,string name,Point point,Point centrality, out Bitmap bitmaps)
{
#region 数据
//标签位置
SolidBrush blue = new SolidBrush(Color.DarkBlue);
//料盘中心点
SolidBrush red = new SolidBrush(Color.Red);
//贴标位置
SolidBrush yeelow = new SolidBrush(Color.Yellow);
Bitmap srcbitmap;
if (File.Exists(pathfile))
{
srcbitmap = new Bitmap(pathfile);
}
else
{
srcbitmap = new Bitmap(3648, 3648);
}
Bitmap bitmap = new Bitmap(srcbitmap);
Graphics g = Graphics.FromImage(bitmap);
Size pointsize = new Size(60, 60);
g.FillEllipse(red, new Rectangle(centrality, pointsize));
Point CalPoint = new Point(point.X, point.Y);
g.FillEllipse(blue, new Rectangle(CalPoint, pointsize));
#endregion
LogNet.log.Info($"标签坐标x={CalPoint.X},y={CalPoint.Y},中心点x={centrality.X},y={centrality.Y}");
Point point_new = new Point();
g.FillEllipse(yeelow, new Rectangle(point, pointsize));
g.Save();
g.Dispose();
ImageSave(bitmap);
bitmaps = bitmap;
return point;
}
public static Point LabelingAngle(string name,Point lable, Point centrality, out int angle)
{
//7寸XY偏移量
int Xpianyilian_7 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_7", 100);
int Ypianyilian_7 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_7", 100);
//7寸朝那个方向贴标true顺时针,false逆时针
bool istoward_7 = ConfigHelper.Config.Get<bool>("Labeling_istoward_7", true);
int degree_7 = ConfigHelper.Config.Get<int>("Labeling_degree_7", 90);
//7寸标签旋转多少度
int Scalerotationdegree_7 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_7", 90);
Point point = lable;
LogNet.log.Info($"7寸料盘,原标签角度={lable};中心点={centrality};");
if (istoward_7)
{
point = ClockwiseRotation(lable, centrality, degree_7);
}
else
{
point = CounterclockwiseRotation(lable, centrality, degree_7);
}
Point Newpoint = new Point(point.X + Xpianyilian_7, point.Y + Ypianyilian_7);
LogNet.log.Info($"7寸料盘,xy轴偏移后位置,x={Newpoint.X},y={Newpoint.Y}");
angle = Scalerotationdegree_7;
return Newpoint;
}
public static Point LabelingAngle_7(Point lable, Point centrality, out int angle)
{
//7寸XY偏移量
int Xpianyilian_7 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_7", 100);
int Ypianyilian_7 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_7", 100);
//7寸朝那个方向贴标true顺时针,false逆时针
bool istoward_7 = ConfigHelper.Config.Get<bool>("Labeling_istoward_7", true);
int degree_7 = ConfigHelper.Config.Get<int>("Labeling_degree_7", 90);
//7寸标签旋转多少度
int Scalerotationdegree_7 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_7", 90);
Point point = lable;
LogNet.log.Info($"7寸料盘,原标签角度={lable};中心点={centrality};");
if (istoward_7)
{
point = ClockwiseRotation(lable, centrality, degree_7);
}
else
{
point = CounterclockwiseRotation(lable, centrality, degree_7);
}
Point Newpoint = new Point(point.X + Xpianyilian_7, point.Y + Ypianyilian_7);
LogNet.log.Info($"7寸料盘,xy轴偏移后位置,x={Newpoint.X},y={Newpoint.Y}");
angle = Scalerotationdegree_7;
return Newpoint;
}
public static Point LabelingAngle_13(Point lable, Point centrality, out int angle)
{
//13寸XY偏移量
int Xpianyilian_13 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_13", 100);
int Ypianyilian_13 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_13", 100);
//13寸朝那个方向贴标true顺时针,false逆时针
bool istoward_13 = ConfigHelper.Config.Get<bool>("Labeling_istoward_13", true);
int degree_13 = ConfigHelper.Config.Get<int>("Labeling_degree_13", 90);
//13寸标签旋转多少度
int Scalerotationdegree_13 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_13", 90);
Point point = lable;
LogNet.log.Info($"13寸料盘,原标签角度={lable};中心点={centrality};");
if (istoward_13)
{
point = ClockwiseRotation(lable, centrality, degree_13);
}
else
{
point = CounterclockwiseRotation(lable, centrality, degree_13);
}
Point Newpoint = new Point(point.X + Xpianyilian_13, point.Y + Ypianyilian_13);
LogNet.log.Info($"13寸料盘,xy轴偏移后位置,x={Newpoint.X},y={Newpoint.Y}");
angle = Scalerotationdegree_13;
return Newpoint;
}
public static Point LabelingAngle_15(Point lable, Point centrality, out int angle)
{
//15寸XY偏移量
int Xpianyilian_15 = ConfigHelper.Config.Get<int>("Labeling_Xpianyilian_15", 100);
int Ypianyilian_15 = ConfigHelper.Config.Get<int>("Labeling_Ypianyilian_15", 100);
//15寸朝那个方向贴标true顺时针,false逆时针
bool istoward_15 = ConfigHelper.Config.Get<bool>("Labeling_istoward_15", true);
int degree_15 = ConfigHelper.Config.Get<int>("Labeling_degree_15", 90);
//15寸标签旋转多少度
int Scalerotationdegree_15 = ConfigHelper.Config.Get<int>("Labeling_Scalerotationdegree_15", 90);
Point point = lable;
LogNet.log.Info($"15寸料盘,原标签角度={lable};中心点={centrality};");
if (istoward_15)
{
point = ClockwiseRotation(lable, centrality, degree_15);
}
else
{
point = CounterclockwiseRotation(lable, centrality, degree_15);
}
Point Newpoint = new Point(point.X + Xpianyilian_15, point.Y + Ypianyilian_15);
LogNet.log.Info($"15寸料盘,xy轴偏移后位置,x={Newpoint.X},y={Newpoint.Y}");
angle = Scalerotationdegree_15;
return Newpoint;
}
/// <summary>
/// 顺时针旋转
/// </summary>
......@@ -243,29 +25,10 @@ namespace DeviceLibrary.AutoScanAndLabel
double theta = angle * Math.PI / 180;
double x_new = (lable.X - center.X) * Math.Cos(theta) - (lable.Y - center.Y) * Math.Sin(theta) + center.X;
double y_new = (lable.X - center.X) * Math.Sin(theta) + (lable.Y - center.Y) * Math.Cos(theta) + center.Y;
LogNet.log.Info($"顺时针旋转{angle}度,x={x_new},y={y_new};");
LogNet.log.Info($"原坐标:{lable},中心点:{center},顺时针旋转:{angle}度,新坐标:x={x_new},y={y_new};");
return new Point((int)x_new, (int)y_new);
}
/// <summary>
/// 逆时针旋转
/// </summary>
/// <param name="lable">标签坐标</param>
/// <param name="center">中心点</param>
/// <param name="angle">旋转角度</param>
/// <returns></returns>
public static Point CounterclockwiseRotation(Point lable, Point center, double angle)
{
lable=ClockwiseRotation(lable, center, 0);
double theta = angle * Math.PI / 180;
//double x, double y, double h, double k, double angle
//double x_new = (x - h) * Math.Cos(theta) + (y - k) * Math.Sin(theta) + h;
//double y_new = -(x - h) * Math.Sin(theta) + (y - k) * Math.Cos(theta) + k;
double x_new = (lable.X - center.X) * Math.Cos(theta) + (lable.Y - center.Y) * Math.Sin(theta) + center.X;
double y_new = -(lable.X - center.X) * Math.Sin(theta) + (lable.Y - center.Y) * Math.Cos(theta) + center.Y;
LogNet.log.Info($"逆时针旋转{angle}度,x={x_new},y={y_new};");
return new Point((int)x_new, (int)y_new);
}
static void ImageSave(Bitmap bitmap)
{
......
......@@ -146,7 +146,7 @@ namespace BLL
keyword = null;
code.ForEach((c) =>
{
LogNet.log.Info($"扫描到 {c.CodeType},{c.Text}");
LogNet.log.Info($"扫描到 {c.Angle}, {c.CodeType},{c.Text}");
});
MatchAnalysis.StartNewAnalysis(code);
if (Config.Func_EnabledOCR)
......@@ -158,7 +158,7 @@ namespace BLL
string currentDirectory = System.Windows.Forms.Application.StartupPath;
string filePath = System.IO.Path.Combine(currentDirectory, "ocr.jpg");
//CurrntBitmap?.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
LogNet.log.Info($"开始保存图片");
LogNet.log.Info($"开始保存图片:{filePath}");
CurrntBitmap?.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
LogNet.log.Info($"保存图片");
......@@ -821,6 +821,12 @@ namespace BLL
var y2 = p1.Y + distance * Math.Sin(angle / 180 * Math.PI);
return new System.Drawing.Point((int)x2, (int)y2);
}
public static System.Drawing.Point PointWithAngle(System.Drawing.Point p1, double angle, double distance)
{
var x2 = p1.X + distance * Math.Cos(angle / 180 * Math.PI);
var y2 = p1.Y + distance * Math.Sin(angle / 180 * Math.PI);
return new System.Drawing.Point((int)x2, (int)y2);
}
//public Dictionary<string, string> ExtractCode(List<MaterialCode> code, int mateIndex)
//{
// Dictionary<string, string> keyword = new Dictionary<string, string>();
......
......@@ -80,7 +80,7 @@ namespace SmartScan
this.BtnOK.BorderWidth = 2;
this.BtnOK.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.BtnOK.HoldPress = false;
this.BtnOK.Location = new System.Drawing.Point(910, 737);
this.BtnOK.Location = new System.Drawing.Point(641, 689);
this.BtnOK.Name = "BtnOK";
this.BtnOK.Padding = new System.Windows.Forms.Padding(3);
this.BtnOK.Size = new System.Drawing.Size(120, 40);
......@@ -96,7 +96,7 @@ namespace SmartScan
this.BtnCancel.BorderWidth = 2;
this.BtnCancel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.BtnCancel.HoldPress = false;
this.BtnCancel.Location = new System.Drawing.Point(1036, 737);
this.BtnCancel.Location = new System.Drawing.Point(767, 689);
this.BtnCancel.Name = "BtnCancel";
this.BtnCancel.Padding = new System.Windows.Forms.Padding(3);
this.BtnCancel.Size = new System.Drawing.Size(120, 40);
......@@ -116,7 +116,7 @@ namespace SmartScan
this.PnlTemp.Location = new System.Drawing.Point(142, 55);
this.PnlTemp.Name = "PnlTemp";
this.PnlTemp.Padding = new System.Windows.Forms.Padding(3);
this.PnlTemp.Size = new System.Drawing.Size(1140, 676);
this.PnlTemp.Size = new System.Drawing.Size(871, 628);
this.PnlTemp.TabIndex = 11;
this.PnlTemp.Text = "facePanel1";
this.PnlTemp.TitleFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
......@@ -130,7 +130,7 @@ namespace SmartScan
this.BtnApply.BorderWidth = 2;
this.BtnApply.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.BtnApply.HoldPress = false;
this.BtnApply.Location = new System.Drawing.Point(1162, 737);
this.BtnApply.Location = new System.Drawing.Point(893, 689);
this.BtnApply.Name = "BtnApply";
this.BtnApply.Padding = new System.Windows.Forms.Padding(3);
this.BtnApply.Size = new System.Drawing.Size(120, 40);
......@@ -145,7 +145,7 @@ namespace SmartScan
this.CboLanguage.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.CboLanguage.BorderWidth = 2;
this.CboLanguage.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.CboLanguage.Location = new System.Drawing.Point(1002, 11);
this.CboLanguage.Location = new System.Drawing.Point(733, 11);
this.CboLanguage.Name = "CboLanguage";
this.CboLanguage.Padding = new System.Windows.Forms.Padding(3);
this.CboLanguage.ReadOnly = true;
......@@ -230,7 +230,7 @@ namespace SmartScan
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.AutoSize = true;
this.ClientSize = new System.Drawing.Size(1293, 788);
this.ClientSize = new System.Drawing.Size(1024, 740);
this.Controls.Add(this.but_Labeling);
this.Controls.Add(this.Keywordlabeling);
this.Controls.Add(this.BtnWorkMode);
......
......@@ -199,144 +199,6 @@ namespace SmartScan.PlusSettingFrm
labelings.Add(labeling);
}
public static System.Drawing.Point LabelingAngle(string name, AMatch aMatch, System.Drawing.Point centrality, bool isvaor, int PlateW, out int angle)
{
System.Drawing.Point lable = aMatch.Points;
var data = labelings.Where(a => a.Name == name).FirstOrDefault();
LogNet.log.Info($"{name}:原标签角度x={lable.X};y={lable.Y};中心点x={centrality.X};y={centrality.Y}");
if (data != null)
{
if (data.IsOverlaylabel)
{
#region 覆盖原标签
//LogNet.log.Info($"{name}:覆盖原标签;是否ID相机={isvaor};");
//aMatch.Points = LabelingPosition.ClockwiseRotation(lable, centrality, 0);
//if (isvaor)
//{
// angle = ScanningCameraAngle(aMatch.Angle);
//}
//else
//{
// angle = OldAngleAlgo(centrality, lable, PlateW);
//}
//LogNet.log.Info($"{name}:覆盖原标签!新标签位置:{aMatch.Points};角度:{angle}");
//return aMatch.Points;
#endregion
return Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, out angle);
}
System.Drawing.Point point = new Point(0, 0);
if (data.IscIockwise)
{
point = LabelingPosition.ClockwiseRotation(lable, centrality, data.RotationAngle);
}
if (data.IsCounterclockwise)
{
point = LabelingPosition.CounterclockwiseRotation(lable, centrality, data.RotationAngle);
}
if (!data.IscIockwise && !data.IsCounterclockwise)
{
return Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, out angle);
}
System.Drawing.Point Newpoint = new System.Drawing.Point(point.X + data.Xoffset, point.Y + data.Yoffset);
angle = data.LabelRotationAngle;
LogNet.log.Info($"{name}:xy轴偏移后位置,x={Newpoint.X},y={Newpoint.Y};角度为:{angle}");
return Newpoint;
}
else
{
LogNet.log.Info($"未找到<{name}>模板:默认覆盖原标签!");
return Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, out angle);
#region 覆盖原标签
//aMatch.Points = LabelingPosition.ClockwiseRotation(lable, centrality, 0);
//if (isvaor)
//{
// angle = ScanningCameraAngle(aMatch.Angle);
//}
//else
//{
// angle = OldAngleAlgo(centrality, lable, PlateW);
//}
//LogNet.log.Info($"未找到<{name}>模板:默认覆盖原标签!新标签位置:{aMatch.Points};角度:{angle}");
//return aMatch.Points;
#endregion
}
}
public static System.Drawing.Point LabelingAngle_New(string name, AMatch aMatch, System.Drawing.Point centrality, bool isvaor, int PlateW, out int angle)
{
System.Drawing.Point label = aMatch.Points;
var data = labelings.FirstOrDefault(a => a.Name == name);
LogNet.log.Info($"{name}:原标签角度x={label.X};y={label.Y};中心点x={centrality.X};y={centrality.Y}");
if (data == null)
{
LogNet.log.Info("未查询到贴标数据,使用覆盖原标签方式;");
return Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, out angle);
}
else
{
if (data.IsOverlaylabel || (!data.IscIockwise && !data.IsCounterclockwise))
{
var position = Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, out angle);
return new Point(position.X+data.Xoffset,position.Y+data.Yoffset);
}
System.Drawing.Point point = new Point(0, 0);
if (data.IscIockwise)
{
point = LabelingPosition.ClockwiseRotation(label, centrality, data.RotationAngle);
}
else if (data.IsCounterclockwise)
{
point = LabelingPosition.CounterclockwiseRotation(label, centrality, data.RotationAngle);
}
System.Drawing.Point newPoint = new System.Drawing.Point(point.X + data.Xoffset, point.Y + data.Yoffset);
angle = data.LabelRotationAngle;
LogNet.log.Info($"{name}:xy轴偏移后位置,x={newPoint.X},y={newPoint.Y};角度为:{angle}");
return newPoint;
}
}
public static Point Overwritelabel(Point centrality, Point lable, bool isvaor, int PlateW, int Angle, out int angle)
{
Point Points = LabelingPosition.ClockwiseRotation(lable, centrality, 0);
if (isvaor)
{
angle = ScanningCameraAngle(Angle);
}
else
{
angle = OldAngleAlgo(centrality, lable, PlateW);
}
LogNet.log.Info($"覆盖原标签!是否id相机={isvaor};新标签位置:{Points};角度:{angle}");
return Points;
}
public static int ScanningCameraAngle(int angles)
{
int angle = 0;
double rotationAngle = 83;
if (angles < 0 && angles != 0)
{
angle = (int)(Math.Abs(angles) + rotationAngle);
}
else
{
if (angles <= 83)
{
angle = (int)Math.Abs(angles - rotationAngle);
}
else
{
angle = 350 - (int)(angles - rotationAngle);
}
}
angle += 90;
if (angle > 344)
{
angle -= 344;
}
return angle;
}
/// <summary>
/// 获取以点为中心的角度,-180~180
/// </summary>
......
......@@ -29,6 +29,7 @@
private void InitializeComponent()
{
this.facePanel1 = new Asa.FaceControl.FacePanel();
this.lab_PlateWs = new System.Windows.Forms.Label();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.UpdateLabel = new Asa.FaceControl.FaceButton();
this.AddLabel = new Asa.FaceControl.FaceButton();
......@@ -44,7 +45,6 @@
this.Yaxisoffset = new Asa.FaceControl.FaceTextBox();
this.Keyvalue = new Asa.FaceControl.FaceTextBox();
this.RotateAngle = new Asa.FaceControl.FaceLabel();
this.lab_PlateWs = new System.Windows.Forms.Label();
this.facePanel1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
......@@ -57,15 +57,27 @@
this.facePanel1.Controls.Add(this.lab_PlateWs);
this.facePanel1.Controls.Add(this.tableLayoutPanel1);
this.facePanel1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.facePanel1.Location = new System.Drawing.Point(119, 55);
this.facePanel1.Location = new System.Drawing.Point(79, 37);
this.facePanel1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.facePanel1.Name = "facePanel1";
this.facePanel1.Padding = new System.Windows.Forms.Padding(3);
this.facePanel1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.facePanel1.ShowText = false;
this.facePanel1.Size = new System.Drawing.Size(1044, 648);
this.facePanel1.Size = new System.Drawing.Size(696, 433);
this.facePanel1.TabIndex = 0;
this.facePanel1.Text = "facePanel1";
this.facePanel1.TitleFont = new System.Drawing.Font("宋体", 12F);
//
// lab_PlateWs
//
this.lab_PlateWs.AutoSize = true;
this.lab_PlateWs.Location = new System.Drawing.Point(564, 6);
this.lab_PlateWs.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lab_PlateWs.Name = "lab_PlateWs";
this.lab_PlateWs.Size = new System.Drawing.Size(11, 12);
this.lab_PlateWs.TabIndex = 3;
this.lab_PlateWs.Text = "0";
this.lab_PlateWs.Visible = false;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 3;
......@@ -86,7 +98,8 @@
this.tableLayoutPanel1.Controls.Add(this.Yaxisoffset, 2, 3);
this.tableLayoutPanel1.Controls.Add(this.Keyvalue, 2, 0);
this.tableLayoutPanel1.Controls.Add(this.RotateAngle, 1, 1);
this.tableLayoutPanel1.Location = new System.Drawing.Point(6, 6);
this.tableLayoutPanel1.Location = new System.Drawing.Point(4, 4);
this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 6;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16F));
......@@ -95,7 +108,7 @@
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 16F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(834, 636);
this.tableLayoutPanel1.Size = new System.Drawing.Size(556, 424);
this.tableLayoutPanel1.TabIndex = 2;
//
// UpdateLabel
......@@ -106,10 +119,11 @@
this.UpdateLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.UpdateLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.UpdateLabel.HoldPress = false;
this.UpdateLabel.Location = new System.Drawing.Point(336, 508);
this.UpdateLabel.Location = new System.Drawing.Point(224, 337);
this.UpdateLabel.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.UpdateLabel.Name = "UpdateLabel";
this.UpdateLabel.Padding = new System.Windows.Forms.Padding(3);
this.UpdateLabel.Size = new System.Drawing.Size(244, 125);
this.UpdateLabel.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.UpdateLabel.Size = new System.Drawing.Size(162, 85);
this.UpdateLabel.TabIndex = 4;
this.UpdateLabel.Text = "修改关键字";
this.UpdateLabel.Click += new System.EventHandler(this.UpdateLabel_Click);
......@@ -122,10 +136,11 @@
this.AddLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.AddLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.AddLabel.HoldPress = false;
this.AddLabel.Location = new System.Drawing.Point(3, 508);
this.AddLabel.Location = new System.Drawing.Point(2, 337);
this.AddLabel.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.AddLabel.Name = "AddLabel";
this.AddLabel.Padding = new System.Windows.Forms.Padding(3);
this.AddLabel.Size = new System.Drawing.Size(327, 125);
this.AddLabel.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.AddLabel.Size = new System.Drawing.Size(218, 85);
this.AddLabel.TabIndex = 1;
this.AddLabel.Text = "添加";
this.AddLabel.Click += new System.EventHandler(this.AddLabel_Click);
......@@ -137,12 +152,13 @@
this.LabelAngle.BorderWidth = 2;
this.LabelAngle.Dock = System.Windows.Forms.DockStyle.Fill;
this.LabelAngle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.LabelAngle.Location = new System.Drawing.Point(586, 407);
this.LabelAngle.Location = new System.Drawing.Point(390, 270);
this.LabelAngle.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.LabelAngle.Name = "LabelAngle";
this.LabelAngle.Padding = new System.Windows.Forms.Padding(3);
this.LabelAngle.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.LabelAngle.SelectedIndex = -1;
this.LabelAngle.SelectedText = "";
this.LabelAngle.Size = new System.Drawing.Size(245, 95);
this.LabelAngle.Size = new System.Drawing.Size(164, 63);
this.LabelAngle.TabIndex = 6;
this.LabelAngle.Text = "0";
//
......@@ -154,10 +170,11 @@
this.SaveLabel.Dock = System.Windows.Forms.DockStyle.Fill;
this.SaveLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.SaveLabel.HoldPress = false;
this.SaveLabel.Location = new System.Drawing.Point(586, 508);
this.SaveLabel.Location = new System.Drawing.Point(390, 337);
this.SaveLabel.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.SaveLabel.Name = "SaveLabel";
this.SaveLabel.Padding = new System.Windows.Forms.Padding(3);
this.SaveLabel.Size = new System.Drawing.Size(245, 125);
this.SaveLabel.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.SaveLabel.Size = new System.Drawing.Size(164, 85);
this.SaveLabel.TabIndex = 3;
this.SaveLabel.Text = "确认";
this.SaveLabel.Click += new System.EventHandler(this.SaveLabel_Click);
......@@ -169,12 +186,13 @@
this.ClockwiseAngle.BorderWidth = 2;
this.ClockwiseAngle.Dock = System.Windows.Forms.DockStyle.Fill;
this.ClockwiseAngle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.ClockwiseAngle.Location = new System.Drawing.Point(586, 104);
this.ClockwiseAngle.Location = new System.Drawing.Point(390, 69);
this.ClockwiseAngle.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.ClockwiseAngle.Name = "ClockwiseAngle";
this.ClockwiseAngle.Padding = new System.Windows.Forms.Padding(3);
this.ClockwiseAngle.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.ClockwiseAngle.SelectedIndex = -1;
this.ClockwiseAngle.SelectedText = "";
this.ClockwiseAngle.Size = new System.Drawing.Size(245, 95);
this.ClockwiseAngle.Size = new System.Drawing.Size(164, 63);
this.ClockwiseAngle.TabIndex = 5;
this.ClockwiseAngle.Text = "0";
//
......@@ -185,16 +203,17 @@
this.keyname.BorderWidth = 2;
this.keyname.Dock = System.Windows.Forms.DockStyle.Fill;
this.keyname.Enabled = false;
this.keyname.Location = new System.Drawing.Point(336, 3);
this.keyname.Location = new System.Drawing.Point(224, 2);
this.keyname.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.keyname.MaxLength = 32767;
this.keyname.Name = "keyname";
this.keyname.Padding = new System.Windows.Forms.Padding(3);
this.keyname.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.keyname.SelectedText = "";
this.keyname.SelectionLength = 0;
this.keyname.SelectionStart = 0;
this.keyname.ShowDel = false;
this.keyname.ShowQuery = false;
this.keyname.Size = new System.Drawing.Size(244, 95);
this.keyname.Size = new System.Drawing.Size(162, 63);
this.keyname.TabIndex = 11;
//
// Xoffset
......@@ -204,10 +223,11 @@
this.Xoffset.BorderWidth = 2;
this.Xoffset.Dock = System.Windows.Forms.DockStyle.Fill;
this.Xoffset.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.Xoffset.Location = new System.Drawing.Point(336, 205);
this.Xoffset.Location = new System.Drawing.Point(224, 136);
this.Xoffset.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Xoffset.Name = "Xoffset";
this.Xoffset.Padding = new System.Windows.Forms.Padding(3);
this.Xoffset.Size = new System.Drawing.Size(244, 95);
this.Xoffset.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Xoffset.Size = new System.Drawing.Size(162, 63);
this.Xoffset.TabIndex = 8;
this.Xoffset.Text = "X轴偏移量";
//
......@@ -218,12 +238,13 @@
this.ListData.BorderWidth = 2;
this.ListData.Dock = System.Windows.Forms.DockStyle.Fill;
this.ListData.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.ListData.Location = new System.Drawing.Point(3, 3);
this.ListData.Location = new System.Drawing.Point(2, 2);
this.ListData.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.ListData.Name = "ListData";
this.ListData.Padding = new System.Windows.Forms.Padding(3);
this.ListData.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.tableLayoutPanel1.SetRowSpan(this.ListData, 5);
this.ListData.SelectedIndex = -1;
this.ListData.Size = new System.Drawing.Size(327, 499);
this.ListData.Size = new System.Drawing.Size(218, 331);
this.ListData.TabIndex = 0;
this.ListData.SelectedIndexChanged += new System.EventHandler(this.ListData_SelectedIndexChanged);
//
......@@ -234,10 +255,11 @@
this.Yoffset.BorderWidth = 2;
this.Yoffset.Dock = System.Windows.Forms.DockStyle.Fill;
this.Yoffset.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.Yoffset.Location = new System.Drawing.Point(336, 306);
this.Yoffset.Location = new System.Drawing.Point(224, 203);
this.Yoffset.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Yoffset.Name = "Yoffset";
this.Yoffset.Padding = new System.Windows.Forms.Padding(3);
this.Yoffset.Size = new System.Drawing.Size(244, 95);
this.Yoffset.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Yoffset.Size = new System.Drawing.Size(162, 63);
this.Yoffset.TabIndex = 9;
this.Yoffset.Text = "Y轴偏移量";
//
......@@ -248,10 +270,11 @@
this.LabelRotation.BorderWidth = 2;
this.LabelRotation.Dock = System.Windows.Forms.DockStyle.Fill;
this.LabelRotation.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.LabelRotation.Location = new System.Drawing.Point(336, 407);
this.LabelRotation.Location = new System.Drawing.Point(224, 270);
this.LabelRotation.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.LabelRotation.Name = "LabelRotation";
this.LabelRotation.Padding = new System.Windows.Forms.Padding(3);
this.LabelRotation.Size = new System.Drawing.Size(244, 95);
this.LabelRotation.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.LabelRotation.Size = new System.Drawing.Size(162, 63);
this.LabelRotation.TabIndex = 10;
this.LabelRotation.Text = "标签旋转角度";
//
......@@ -261,16 +284,17 @@
this.Xaxisoffset.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.Xaxisoffset.BorderWidth = 2;
this.Xaxisoffset.Dock = System.Windows.Forms.DockStyle.Fill;
this.Xaxisoffset.Location = new System.Drawing.Point(586, 205);
this.Xaxisoffset.Location = new System.Drawing.Point(390, 136);
this.Xaxisoffset.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Xaxisoffset.MaxLength = 32767;
this.Xaxisoffset.Name = "Xaxisoffset";
this.Xaxisoffset.Padding = new System.Windows.Forms.Padding(3);
this.Xaxisoffset.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Xaxisoffset.SelectedText = "";
this.Xaxisoffset.SelectionLength = 0;
this.Xaxisoffset.SelectionStart = 0;
this.Xaxisoffset.ShowDel = true;
this.Xaxisoffset.ShowQuery = false;
this.Xaxisoffset.Size = new System.Drawing.Size(245, 95);
this.Xaxisoffset.Size = new System.Drawing.Size(164, 63);
this.Xaxisoffset.TabIndex = 4;
this.Xaxisoffset.Text = "0";
//
......@@ -280,16 +304,17 @@
this.Yaxisoffset.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.Yaxisoffset.BorderWidth = 2;
this.Yaxisoffset.Dock = System.Windows.Forms.DockStyle.Fill;
this.Yaxisoffset.Location = new System.Drawing.Point(586, 306);
this.Yaxisoffset.Location = new System.Drawing.Point(390, 203);
this.Yaxisoffset.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Yaxisoffset.MaxLength = 32767;
this.Yaxisoffset.Name = "Yaxisoffset";
this.Yaxisoffset.Padding = new System.Windows.Forms.Padding(3);
this.Yaxisoffset.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Yaxisoffset.SelectedText = "";
this.Yaxisoffset.SelectionLength = 0;
this.Yaxisoffset.SelectionStart = 0;
this.Yaxisoffset.ShowDel = true;
this.Yaxisoffset.ShowQuery = false;
this.Yaxisoffset.Size = new System.Drawing.Size(245, 95);
this.Yaxisoffset.Size = new System.Drawing.Size(164, 63);
this.Yaxisoffset.TabIndex = 5;
this.Yaxisoffset.Text = "0";
//
......@@ -299,16 +324,17 @@
this.Keyvalue.BorderStyle = Asa.FaceControl.ControlShape.Rectangle;
this.Keyvalue.BorderWidth = 2;
this.Keyvalue.Dock = System.Windows.Forms.DockStyle.Fill;
this.Keyvalue.Location = new System.Drawing.Point(586, 3);
this.Keyvalue.Location = new System.Drawing.Point(390, 2);
this.Keyvalue.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Keyvalue.MaxLength = 32767;
this.Keyvalue.Name = "Keyvalue";
this.Keyvalue.Padding = new System.Windows.Forms.Padding(3);
this.Keyvalue.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Keyvalue.SelectedText = "";
this.Keyvalue.SelectionLength = 0;
this.Keyvalue.SelectionStart = 0;
this.Keyvalue.ShowDel = true;
this.Keyvalue.ShowQuery = false;
this.Keyvalue.Size = new System.Drawing.Size(245, 95);
this.Keyvalue.Size = new System.Drawing.Size(164, 63);
this.Keyvalue.TabIndex = 1;
//
// RotateAngle
......@@ -318,30 +344,22 @@
this.RotateAngle.BorderWidth = 2;
this.RotateAngle.Dock = System.Windows.Forms.DockStyle.Fill;
this.RotateAngle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
this.RotateAngle.Location = new System.Drawing.Point(336, 104);
this.RotateAngle.Location = new System.Drawing.Point(224, 69);
this.RotateAngle.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.RotateAngle.Name = "RotateAngle";
this.RotateAngle.Padding = new System.Windows.Forms.Padding(3);
this.RotateAngle.Size = new System.Drawing.Size(244, 95);
this.RotateAngle.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.RotateAngle.Size = new System.Drawing.Size(162, 63);
this.RotateAngle.TabIndex = 7;
this.RotateAngle.Text = "以特征码顺时针旋转角度";
//
// lab_PlateWs
//
this.lab_PlateWs.AutoSize = true;
this.lab_PlateWs.Location = new System.Drawing.Point(846, 9);
this.lab_PlateWs.Name = "lab_PlateWs";
this.lab_PlateWs.Size = new System.Drawing.Size(26, 27);
this.lab_PlateWs.TabIndex = 3;
this.lab_PlateWs.Text = "0";
this.lab_PlateWs.Visible = false;
//
// UsrKeywordlabeling
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.facePanel1);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "UsrKeywordlabeling";
this.Size = new System.Drawing.Size(1317, 773);
this.Size = new System.Drawing.Size(878, 515);
this.facePanel1.ResumeLayout(false);
this.facePanel1.PerformLayout();
this.tableLayoutPanel1.ResumeLayout(false);
......
using Asa.FaceControl;
using BLL;
using DeviceLibrary.AutoScanAndLabel;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.EMMA;
......@@ -258,13 +259,13 @@ namespace SmartScan.PlusSettingFrm
item.key = "";
}
}
public static System.Drawing.Point LabelingAngle(string keyvalue, AMatch aMatch, System.Drawing.Point centrality, bool isvaor, int PlateW, out int angle)
public static Point LabelingAngle(string keyvalue, AMatch aMatch, System.Drawing.Point centrality, bool isvaor, int PlateW, out int angle)
{
Point lable = aMatch.Points;
Point newpoint = aMatch.Points;
var Data = labels.FirstOrDefault(a => a.value == keyvalue);
int RotateAngle = 0;
int X = 0, Y = 0;
//int X = 0, Y = 0;
if (Data==null&&labels.Count>0)
{
Data = labels.FirstOrDefault(a=>a.Primarykey&&a.PlateW==PlateW);
......@@ -272,53 +273,59 @@ namespace SmartScan.PlusSettingFrm
if (Data!=null)
{
RotateAngle = Data.ClockwiseAngle;
X += Data.X; Y += Data.Y;
//X += Data.X; Y += Data.Y;
LogUtil.info($"关键字{Data.key}={Data.value};顺时针旋转角度={Data.ClockwiseAngle};xy偏移{Data.X};{Data.Y};标签角度:{Data.LabelAngle}");
}
newpoint = Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, RotateAngle, out angle);
if (Data != null&&Data.LabelAngle > 0)
{
angle = Data.LabelAngle;
newpoint = Overwritelabel(centrality, aMatch.Points, isvaor, PlateW, aMatch.Angle, RotateAngle, out angle);
//if (Data != null&&Data.LabelAngle > 0)
//{
// angle = Data.LabelAngle;
//}
if (Data.X != 0) {
newpoint= MaterialEdit.PointWithAngle(newpoint, angle - 90, Data.X);
}
if (Data.Y != 0)
{
newpoint = MaterialEdit.PointWithAngle(newpoint, angle, Data.Y);
}
return new Point(newpoint.X + X, newpoint.Y + Y);
LogUtil.info($"处理后角度={angle};处理后贴标位置:{newpoint};标签变换角度:{Data.LabelAngle}");
return new Point(newpoint.X, newpoint.Y);
}
public static Point Overwritelabel(Point centrality, Point lable, bool isvaor, int PlateW, int Angle,int RotateAngle, out int angle)
{
Point Points = LabelingPosition.ClockwiseRotation(lable, centrality, RotateAngle);
if (isvaor)
{
angle = ScanningCameraAngle(Angle);
angle = ScanningCameraAngle(Angle, RotateAngle);
}
else
{
angle = OldAngleAlgo(centrality, lable, PlateW);
}
LogNet.log.Info($"是否id相机={isvaor};新标签位置:{Points};角度:{angle}");
LogNet.log.Info($"是否id相机={isvaor};新标签位置:{Points};输入角度:{Angle},设定偏转:{RotateAngle},转换后角度:{angle}");
return Points;
}
public static int ScanningCameraAngle(int angles)
public static int ScanningCameraAngle(int angles, int RotateAngle)
{
int angle = 0;
double rotationAngle = 83;
if (angles < 0 && angles != 0)
//ID MVS相机, 右侧为正角度, 左侧为负角度
int angle;
int rotationAngle = RotateAngle+83;// 83;
if (angles < 0)
{
angle = (int)(Math.Abs(angles) + rotationAngle);
angle = angles * -1 + rotationAngle;
}
else
{
if (angles <= 83)
{
angle = (int)Math.Abs(angles - rotationAngle);
}
else
{
angle = 350 - (int)(angles - rotationAngle);
}
angle = 360 - angles + rotationAngle;
}
angle += 90;
if (angle > 344)
if (angle >= 360)
{
angle -= 360;
}
else if (angle < 0)
{
angle -= 344;
angle = 360 + angle;
}
return angle;
}
......
using BLL;
using HalconDotNet;
using Model;
using System;
using System.Collections.Generic;
......
......@@ -233,10 +233,11 @@ namespace SmartScan
System.Threading.Thread.Sleep(100); //光源打开有一个由暗变亮的过程
}
List<Bitmap> image = new List<Bitmap>(Camera.CaptureAndGetCode(out workCodeInfo));
if (image.Count > 0 && !BLL.Config.Backgrounder) picShow.Image = image[0];
if (image.Count > 0)
{
BLLCommon.mateEdit.CurrntBitmap = image[0];
BLLCommon.mateEdit.CurrntBitmap = WebCallWork.DeepClone(image[0]);
if (!BLL.Config.Backgrounder)
picShow.Image = image[0];
if (BLLCommon.mateEdit.CurrntBitmap!=null)
_ = UnifiedDataHandler.PostSmfImageAsync(BLLCommon.mateEdit.CurrntBitmap, new Dictionary<string, string> { { "cid", BLLCommon.config.CID + "_1" } }, BLLCommon.mateEdit.CurrntBitmap.Width, BLLCommon.mateEdit.CurrntBitmap.Height);
}
......
......@@ -69,16 +69,16 @@ namespace SmartScan
if (workCodeInfo.Count == 0)
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败" };
BLLCommon.mateEdit.CurrntBitmap = bitmap;
BLLCommon.mateEdit.CurrntBitmap = DeepClone(bitmap);
bool rtn = BLLCommon.mateEdit.MatchingTemplate(workCodeInfo, BLLCommon.config.DefaultMaterialName, false, out string mateName, out workCodeKeyword, out AMatch aMatch);
LogNet.log.Info("模板匹配结果:" + rtn);
WebResultCode webResultCode = null;
Dictionary<string,string> keys=new Dictionary<string, string> ();
Dictionary<string, string> keys = new Dictionary<string, string>();
foreach (var item in workCodeKeyword)
{
// workCodeKeyword[item.Key]= item.Value.Replace("<OCR>", "");
keys.Add(item.Key,item.Value.Replace("<OCR>",""));
// workCodeKeyword[item.Key]= item.Value.Replace("<OCR>", "");
keys.Add(item.Key, item.Value.Replace("<OCR>", ""));
}
if (!BLLCommon.extension.SetKey(null, keys, rtn, out string errmsg))
{
......@@ -89,7 +89,7 @@ namespace SmartScan
return webResultCode;
LogNet.log.Info("模板匹配结束");
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
#region 判断是否需要请求http替换数据
workCodeKeyword = WebserverReplaceData(keys);
//bool isReplaceData = ConfigHelper.Config.Get<bool>("WebServer_isReplaceData", false);
......@@ -138,10 +138,35 @@ namespace SmartScan
LogNet.log.Error("ProcessBitmap", ex);
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败:" + ex };
}
finally {
bitmap?.Dispose();
}
}
public static T DeepClone<T>(T _object)
{
try
{
T dstobject;
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, _object);
mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
dstobject = (T)bf.Deserialize(mStream);
mStream.Close();
}
return dstobject;
}
catch (Exception e)
{
LogNet.log.Error("DeepClone" , e);
return default;
}
}
public WebResultCode ProcessBitmaps(BitmapData bitmapData)
{
BLLCommon.mateEdit.CurrntBitmap?.Dispose();
Bitmap bitmap = null;
try
{
if (bitmapData == null)
......@@ -154,18 +179,18 @@ namespace SmartScan
}
byte[] imageData = Convert.FromBase64String(bitmapData.ImageData);
Bitmap bitmap = null;
using(MemoryStream stream = new MemoryStream(imageData))
using (MemoryStream stream = new MemoryStream(imageData))
{
bitmap = new Bitmap(stream);
}
if (bitmap==null)
if (bitmap == null)
{
return new WebResultCode() { ErrorCode = -1, Msg = "图片解析完成为空;" };
}
List<CameraVisionLib.Model.BarcodeInfo> workCodeInfo = new();
if (bitmapData.BarCodeList == null&&bitmapData.IsIDCamera)
if (bitmapData.BarCodeList == null && bitmapData.IsIDCamera)
{
return new WebResultCode() { ErrorCode = -1, Msg = "扫码相机未传来条码数据;" };
}
......@@ -190,20 +215,20 @@ namespace SmartScan
if (workCodeInfo.Count == 0)
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败" };
}
BLLCommon.mateEdit.CurrntBitmap = bitmap;
}
BLLCommon.mateEdit.CurrntBitmap = DeepClone(bitmap);
Dictionary<string, string> workCodeKeyword;
bool rtn = BLLCommon.mateEdit.MatchingTemplate(workCodeInfo, BLLCommon.config.DefaultMaterialName, false, out string mateName, out workCodeKeyword, out AMatch aMatch);
var point=new Point(-1,-1);
var point = new Point(-1, -1);
int angle = 0;
LogNet.log.Info("模板匹配结果:" + rtn);
if (rtn)
{
string key = ConfigHelper.Config.Get("Label_Key", "");
workCodeKeyword.TryGetValue(key, out String Value);
LogNet.log.Info("模板匹配结果:" + rtn + $";关键字{key}:{Value};匹配成功条码xy:X={aMatch.Points.X};Y={aMatch.Points.Y},中心点x={bitmapData.X};y={bitmapData.Y},角度={aMatch.Angle},料盘尺寸={bitmapData.PlateW};匹配成功条码:{string.Join(", ", aMatch.IsCodeUsed)}" );
point=UsrKeywordlabeling.LabelingAngle(Value, aMatch, new Point(bitmapData.X, bitmapData.Y), bitmapData.IsIDCamera, bitmapData.PlateW, out angle);
LogNet.log.Info("模板匹配结果:" + rtn + $";关键字{key}:{Value};匹配成功条码xy:X={aMatch.Points.X};Y={aMatch.Points.Y},中心点x={bitmapData.X};y={bitmapData.Y},角度={aMatch.Angle},料盘尺寸={bitmapData.PlateW};匹配成功条码:{string.Join(", ", aMatch.IsCodeUsed)}");
point = UsrKeywordlabeling.LabelingAngle(Value, aMatch, new Point(bitmapData.X, bitmapData.Y), bitmapData.IsIDCamera, bitmapData.PlateW, out angle);
//point =UsrCustomlabeling.LabelingAngle_New(mateName, aMatch, new Point(bitmapData.X, bitmapData.Y), bitmapData.IsIDCamera, bitmapData.PlateW, out angle);
}
Dictionary<string, string> keys = new Dictionary<string, string>();
......@@ -213,26 +238,32 @@ namespace SmartScan
}
if (!BLLCommon.extension.SetKey(null, keys, rtn, out string errmsg))
{
return new WebResultCode() { ErrorCode = -2, Msg = errmsg };
return new WebResultCode() { ErrorCode = -2, Msg = errmsg };
}
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
workCodeKeyword=WebserverReplaceData(keys);
workCodeKeyword = WebserverReplaceData(keys);
foreach (var wc in workCodeKeyword)
{
result.Add(new KeyValuePair<string, string>(wc.Key, wc.Value));
}
NewPositionAngle newPosition = new NewPositionAngle
NewPositionAngle newPosition = new NewPositionAngle
{
X= point.X, Y= point.Y,Angle= angle,IsCodeUsed=aMatch.IsCodeUsed
X = point.X,
Y = point.Y,
Angle = angle,
IsCodeUsed = aMatch.IsCodeUsed
};
LogNet.log.Info($"返回坐标及角度X={newPosition.X};Y={newPosition.Y};角度={newPosition.Angle}");
return new WebResultCode() { workCodeKeyword = result, workCodeInfo = workCodeInfo, PositionAngle= newPosition };
return new WebResultCode() { workCodeKeyword = result, workCodeInfo = workCodeInfo, PositionAngle = newPosition };
}
catch (Exception ex)
{
LogNet.log.Error("ProcessBitmaps", ex);
return new WebResultCode() { ErrorCode = -1, Msg = "扫码失败:" + ex };
}
finally {
bitmap?.Dispose();
}
}
public Dictionary<string, string> WebserverReplaceData(Dictionary<string, string> workCodeKeyword)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!