1、更改所有位置显示窗体为自定义窗体,添加坐标及灰度显示

2、添加工具移除功能
3、PMA工具添加修改模板和定义搜索区域
This commit is contained in:
liu.wenjie
2022-04-14 16:05:10 +08:00
parent e89283dda0
commit 9eb84c6265
30 changed files with 580 additions and 332 deletions

View File

@@ -29,15 +29,17 @@ namespace ViewROI
private void InitializeComponent()
{
this.SmartWindow = new HalconDotNet.HSmartWindowControl();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.lb_Status = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip.SuspendLayout();
this.uiContextMenuStrip1 = new Sunny.UI.UIContextMenuStrip();
this.tsmiDispCorr = new System.Windows.Forms.ToolStripMenuItem();
this.grayValueLable = new Sunny.UI.UISymbolLabel();
this.uiContextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// SmartWindow
//
this.SmartWindow.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.SmartWindow.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange;
this.SmartWindow.ContextMenuStrip = this.uiContextMenuStrip1;
this.SmartWindow.Dock = System.Windows.Forms.DockStyle.Fill;
this.SmartWindow.HDoubleClickToFitContent = true;
this.SmartWindow.HDrawingObjectsModifier = HalconDotNet.HSmartWindowControl.DrawingObjectsModifier.None;
@@ -53,45 +55,57 @@ namespace ViewROI
this.SmartWindow.WindowSize = new System.Drawing.Size(576, 457);
this.SmartWindow.HMouseMove += new HalconDotNet.HMouseEventHandler(this.SmartWindow_HMouseMove);
//
// statusStrip
// uiContextMenuStrip1
//
this.statusStrip.BackColor = System.Drawing.Color.White;
this.statusStrip.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.lb_Status});
this.statusStrip.Location = new System.Drawing.Point(0, 435);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(576, 22);
this.statusStrip.TabIndex = 1;
this.statusStrip.Text = "statusStrip1";
this.statusStrip.Visible = false;
this.uiContextMenuStrip1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.uiContextMenuStrip1.IsScaled = false;
this.uiContextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmiDispCorr});
this.uiContextMenuStrip1.Name = "uiContextMenuStrip1";
this.uiContextMenuStrip1.Size = new System.Drawing.Size(145, 30);
//
// lb_Status
// tsmiDispCorr
//
this.lb_Status.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lb_Status.Name = "lb_Status";
this.lb_Status.Size = new System.Drawing.Size(0, 17);
this.tsmiDispCorr.Name = "tsmiDispCorr";
this.tsmiDispCorr.Size = new System.Drawing.Size(144, 26);
this.tsmiDispCorr.Text = "显示坐标";
this.tsmiDispCorr.Click += new System.EventHandler(this.tsmiDispCorr_Click);
//
// grayValueLable
//
this.grayValueLable.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.grayValueLable.BackColor = System.Drawing.Color.Transparent;
this.grayValueLable.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.grayValueLable.IsScaled = false;
this.grayValueLable.Location = new System.Drawing.Point(3, 430);
this.grayValueLable.MinimumSize = new System.Drawing.Size(1, 1);
this.grayValueLable.Name = "grayValueLable";
this.grayValueLable.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.grayValueLable.Size = new System.Drawing.Size(260, 26);
this.grayValueLable.Symbol = 61483;
this.grayValueLable.TabIndex = 4;
this.grayValueLable.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.grayValueLable.Visible = false;
//
// HWindowTool_Smart
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.statusStrip);
this.Controls.Add(this.grayValueLable);
this.Controls.Add(this.SmartWindow);
this.Name = "HWindowTool_Smart";
this.Size = new System.Drawing.Size(576, 457);
this.Load += new System.EventHandler(this.HWindowTool_Smart_Load);
this.SizeChanged += new System.EventHandler(this.HWindowTool_Smart_SizeChanged);
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.uiContextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.StatusStrip statusStrip;
private System.Windows.Forms.ToolStripStatusLabel lb_Status;
public HalconDotNet.HSmartWindowControl SmartWindow;
private Sunny.UI.UIContextMenuStrip uiContextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem tsmiDispCorr;
private Sunny.UI.UISymbolLabel grayValueLable;
}
}

View File

@@ -14,6 +14,8 @@ namespace ViewROI
{
public bool DispStatus { get; set; }
public HImage hv_Image { get; set; }
HTuple hv_Width = new HTuple();
HTuple hv_Height = new HTuple();
public HWindow DispHWindow
{
get
@@ -27,22 +29,112 @@ namespace ViewROI
}
public void DispImage(HObject inputImage)
{
statusStrip.BackColor = Color.White;
if (inputImage == null || !inputImage.IsInitialized())
{
this.lb_Status.Text = "输入图像为空,请检查!";
statusStrip.BackColor = Color.Red;
return;
}
this.SmartWindow.HalconWindow.DispImage(new HImage(inputImage));
#region
//获取图像大小及纵横比
HOperatorSet.GetImageSize(inputImage, out hv_Width, out hv_Height);
int im_width = int.Parse(hv_Width.ToString());
int im_height = int.Parse(hv_Height.ToString());
double im_AspectRatio = (double)(im_width) / (double)(im_height);
//获取窗口大小及纵横比
int w_width = SmartWindow.Size.Width;
int w_height = SmartWindow.Size.Height;
double w_AspectRatio = (double)(w_width) / (double)(w_height);
HOperatorSet.SetSystem("int_zooming", "false");//图像缩放之前最好将此参数设置为false.
HTuple para = new HTuple("constant");
HObject ho_zoomImage;
HOperatorSet.GenEmptyObj(out ho_zoomImage);
ho_zoomImage.Dispose();
if (w_width < im_width && im_AspectRatio > w_AspectRatio)
{
//超宽图像
HOperatorSet.ZoomImageSize(inputImage, out ho_zoomImage, w_width, w_width / im_AspectRatio, para);
}
else if (w_height < im_height && im_AspectRatio < w_AspectRatio)
{
//超高图像
HOperatorSet.ZoomImageSize(inputImage, out ho_zoomImage, w_height * im_AspectRatio, w_height, para);
}
#endregion
SmartWindow.HalconWindow.SetPart(0, 0,-2, -2);
hv_Image = new HImage(inputImage);
SmartWindow.HalconWindow.DispImage(hv_Image);
ho_zoomImage.Dispose();
hv_Width.Dispose();
hv_Height.Dispose();
}
private void SmartWindow_HMouseMove(object sender, HalconDotNet.HMouseEventArgs e)
{
this.Cursor = e.Button == MouseButtons.Left ? Cursors.Hand : Cursors.Default;
// this.Cursor = e.Button == MouseButtons.Left ? Cursors.Hand : Cursors.Default;
if(DispStatus)
{
if (hv_Image != null && hv_Image.IsInitialized())
{
try
{
int button_state;
double positionX, positionY;
string str_value;
string str_position;
bool _isXOut = true, _isYOut = true;
HTuple channel_count;
HOperatorSet.CountChannels(hv_Image, out channel_count);
SmartWindow.HalconWindow.GetMpositionSubPix(out positionY, out positionX, out button_state);
str_position = String.Format("RC: {0:0},{1:0}", positionY, positionX);
_isXOut = (positionX < 0 || positionX >= hv_Width);
_isYOut = (positionY < 0 || positionY >= hv_Height);
if (!_isXOut && !_isYOut)
{
if ((int)channel_count == 1)
{
double grayVal;
grayVal = hv_Image.GetGrayval((int)positionY, (int)positionX);
str_value = String.Format("Val: {0:000}", grayVal);
}
else if ((int)channel_count == 3)
{
double grayValRed, grayValGreen, grayValBlue;
HImage _RedChannel, _GreenChannel, _BlueChannel;
_RedChannel = hv_Image.AccessChannel(1);
_GreenChannel = hv_Image.AccessChannel(2);
_BlueChannel = hv_Image.AccessChannel(3);
grayValRed = _RedChannel.GetGrayval((int)positionY, (int)positionX);
grayValGreen = _GreenChannel.GetGrayval((int)positionY, (int)positionX);
grayValBlue = _BlueChannel.GetGrayval((int)positionY, (int)positionX);
_RedChannel.Dispose();
_GreenChannel.Dispose();
_BlueChannel.Dispose();
str_value = String.Format("Gray: ({0:000}, {1:000}, {2:000})", grayValRed, grayValGreen, grayValBlue);
}
else
{
str_value = "";
}
grayValueLable.Text = $"Ch{channel_count.D }, {str_position}: {str_value}";
}
}
catch (Exception ex)
{
//不处理
}
}
}
}
@@ -64,5 +156,21 @@ namespace ViewROI
//Point pt2 = SmartWindow.PointToScreen(pt);
//this.SmartWindow.HalconWindow.SendMouseDoubleClickEvent(pt2.X+20, pt2.Y+30,(int)MouseButtons.Left);
}
private void tsmiDispCorr_Click(object sender, EventArgs e)
{
if(tsmiDispCorr.Checked)
{
tsmiDispCorr.Checked = false;
DispStatus = false;
grayValueLable.Visible = false;
}
else
{
tsmiDispCorr.Checked = true;
DispStatus = true;
grayValueLable.Visible = true;
}
}
}
}

View File

@@ -112,12 +112,12 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
<metadata name="uiContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>16, 14</value>
</metadata>
</root>

View File

@@ -112,20 +112,20 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="m_CtrlImageList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="m_CtrlImageList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="m_CtrlImageList.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADk
CAAAAk1TRnQBSQFMAgEBAgEAARABAQEQAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAASABAQEgAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
@@ -166,7 +166,7 @@
Cw==
</value>
</data>
<metadata name="mCtrl_HWindow.LayoutBitmap" type="System.Resources.ResXNullRef, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="mCtrl_HWindow.LayoutBitmap" type="System.Resources.ResXNullRef, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value />
</metadata>
</root>

View File

@@ -84,6 +84,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\MVTec\HALCON-19.05-Progress\bin\dotnet20\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="SunnyUI">
<HintPath>..\VisionEdit\bin\Debug\ThirdLib\SunnyUI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />