You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.9 KiB
C#

using HalconDotNet;
using Rs.Controls;
using Rs.Framework;
using Rs.MotionPlat.Commom;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
namespace Rs.MotionPlat.Recipe
{
public partial class DownCameraLocationRecipe : BaseForm
{
public DownCameraLocationRecipe()
{
InitializeComponent();
cameraTemplate1.SetFindShapeMode( EFindShapeMode.SelfDefine );
cameraTemplate1.FindShapeEvent += CameraTemplate1_FindShapeEvent;
cameraTemplate1.ItemName = "下定位相机";
}
private void CameraTemplate1_FindShapeEvent(ChoiceTech.Halcon.Control.HWindow_Final arg1, HalconDotNet.HObject arg2)
{
if(checkBox1.Checked)
{
VisionProcess.Instance.Reload();
List<MatchResult> result = VisionProcess.Instance.MatchDownCam(new HalconDotNet.HObject[] { arg2 }, false);
if (result != null && result.Count() > 0)
{
HOperatorSet.GenRectangle1(out HObject searchRegion, new HTuple(SysConfigParam.GetValue<int>("CodeRow1")), new HTuple(SysConfigParam.GetValue<int>("CodeColumn1")), new HTuple(SysConfigParam.GetValue<int>("CodeRow2")), new HTuple(SysConfigParam.GetValue<int>("CodeColumn2")));
arg1.DispObj(result[0].ContourXld, "green");
arg1.DispObj(searchRegion, "green");
HalconTool.DispMessage(arg1.hWindowControl.HalconWindow, result[0].SN, 20, 20, "green");
HalconTool.DispMessage(arg1.hWindowControl.HalconWindow, $"x:{result[0].OffsetCol.ToString("0.000")}", 200, 20, "green");
HalconTool.DispMessage(arg1.hWindowControl.HalconWindow, $"y:{result[0].OffsetRow.ToString("0.000")}", 400, 20, "green");
HalconTool.DispMessage(arg1.hWindowControl.HalconWindow, $"r:{result[0].OffsetA.ToString("0.000")}", 600, 20, "green");
LogHelper.Debug($"sn:{result[0].SN},x:{result[0].OffsetCol},y:{result[0].OffsetRow},a:{result[0].OffsetA}");
//Msg.ShowInfo($"sn:{result[0].SN},X:{result[0].OffsetRow},Y:{result[0].OffsetCol},A{result[0].OffsetA}");
File.AppendAllText("c://code.txt", result[0].SN + Environment.NewLine);
}
}
}
private void cameraTemplate1_Load(object sender, EventArgs e)
{
}
private void DownCameraLocationRecipe_Load(object sender, EventArgs e)
{
PositionHelper.BindPosition(groupBox1);
}
public void txtSysParam_KeyUp(object sender, KeyEventArgs e)
{
UpdateSysParam((TextBox)sender);
}
}
}