5023 lines
190 KiB
C#
5023 lines
190 KiB
C#
using Community;
|
||
using DAL;
|
||
using HalconDotNet;
|
||
using MahApps.Metro.Controls.Dialogs;
|
||
using Microsoft.Win32;
|
||
using Model;
|
||
using Model.Vision;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.ObjectModel;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Threading;
|
||
using System.Windows;
|
||
using System.Windows.Threading;
|
||
using ViewModel.Robots;
|
||
using Views.Vision;
|
||
|
||
namespace ViewModel.Vision
|
||
{
|
||
/// <summary>
|
||
/// Halcon视觉类
|
||
/// </summary>
|
||
public partial class HalconVisual : NotificationObject
|
||
{
|
||
public VisualDAL Vdal = new VisualDAL();
|
||
|
||
/// <summary>
|
||
/// 上报异常的委托
|
||
/// </summary>
|
||
/// <param name="hv"></param>
|
||
public delegate void delegeateExcep(string hv);
|
||
/// <summary>
|
||
/// 上报异常的委托事件
|
||
/// </summary>
|
||
public event delegeateExcep eventExcepReport;
|
||
|
||
#region 视觉窗口对象
|
||
private AOI myWindow;
|
||
/// <summary>
|
||
/// 视觉窗口对象
|
||
/// </summary>
|
||
public AOI MyWindow
|
||
{
|
||
get { return myWindow; }
|
||
set
|
||
{
|
||
myWindow = value;
|
||
this.RaisePropertyChanged("MyWindow");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 显示权限
|
||
private Visibility displayLevel;
|
||
/// <summary>
|
||
/// 显示权限
|
||
/// </summary>
|
||
public Visibility DisplayLevel
|
||
{
|
||
get { return displayLevel; }
|
||
set
|
||
{
|
||
displayLevel = value;
|
||
if (value == Visibility.Collapsed)
|
||
{
|
||
ControlShow = "0";
|
||
|
||
}
|
||
else
|
||
{
|
||
ControlShow = "30*";
|
||
}
|
||
this.RaisePropertyChanged("DisplayLevel");
|
||
}
|
||
}
|
||
|
||
#region 超级权限
|
||
private Visibility superPrivilege;
|
||
/// <summary>
|
||
/// 超级权限
|
||
/// </summary>
|
||
public Visibility SuperPrivilege
|
||
{
|
||
get { return superPrivilege; }
|
||
set
|
||
{
|
||
superPrivilege = value;
|
||
this.RaisePropertyChanged("SuperPrivilege");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 视觉控件显示的状态
|
||
|
||
private string controlShow;
|
||
/// <summary>
|
||
/// 相机设置控件是否显示
|
||
/// </summary>
|
||
public string ControlShow
|
||
{
|
||
get { return controlShow; }
|
||
set
|
||
{
|
||
controlShow = value;
|
||
RaisePropertyChanged("ControlShow");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
#endregion
|
||
|
||
#region 机器人对象
|
||
private FeiYuRobotVM robot;
|
||
/// <summary>
|
||
/// 机器人对象
|
||
/// </summary>
|
||
public FeiYuRobotVM Robot
|
||
{
|
||
get { return robot; }
|
||
set
|
||
{
|
||
robot = value;
|
||
RaisePropertyChanged("Robot");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 视觉工程项目集合
|
||
private ObservableCollection<VisualEngineering> visualEngineeringList;
|
||
/// <summary>
|
||
/// 视觉工程项目集合
|
||
/// </summary>
|
||
public ObservableCollection<VisualEngineering> VisualEngineeringList
|
||
{
|
||
get { return visualEngineeringList; }
|
||
set
|
||
{
|
||
visualEngineeringList = value;
|
||
this.RaisePropertyChanged("VisualEngineeringList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 当前使用的相机类型
|
||
/// <summary>
|
||
/// 当前使用的相机类型,即第几个相关
|
||
/// </summary>
|
||
public int CameraType { get; set; }
|
||
#endregion
|
||
|
||
#region 视觉对应的生产机种
|
||
private MachineModel machineObj;
|
||
/// <summary>
|
||
/// 视觉对应的生产机种
|
||
/// </summary>
|
||
public MachineModel MachineObj
|
||
{
|
||
get { return machineObj; }
|
||
set
|
||
{
|
||
machineObj = value;
|
||
if (value.ID > 0)
|
||
{
|
||
//Camera = Vdal.GetCamera(value.ID, CameraType);//获取相机对象
|
||
//Camera.eventProcessImage += ProcessHImage; // 注册halcon显示回调函数
|
||
|
||
// Camera.resolvingPowerSet += SetResolvingPower; //注册分辨率设置事件
|
||
|
||
VisualEngineeringList = Vdal.GetVisualEngineeringList(MachineObj.ID, Camera.ID); //获取相机对应的视觉工程项目集合
|
||
|
||
}
|
||
this.RaisePropertyChanged("MachineObj");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 是否要执行显示图像的委托
|
||
/// </summary>
|
||
public bool Buzhixing { get; set; }
|
||
/// <summary>
|
||
/// 图像委托实现
|
||
/// </summary>
|
||
/// <param name="image"></param>
|
||
public void ProcessHImage(HObject image)
|
||
{
|
||
if (Buzhixing)
|
||
{
|
||
if (image != null)
|
||
{
|
||
Ho_Image = image;
|
||
ClearObjData();
|
||
ShowObj(Ho_Image);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region Halcon图像显示控件
|
||
private HWindowControlWPF hWindowWPF;
|
||
/// <summary>
|
||
/// Halcon图像显示控件
|
||
/// </summary>
|
||
public HWindowControlWPF HWindowWPF
|
||
{
|
||
get { return hWindowWPF; }
|
||
set
|
||
{
|
||
hWindowWPF = value;
|
||
RaisePropertyChanged("HWindowWPF");
|
||
}
|
||
}
|
||
|
||
|
||
private HSmartWindowControlWPF hWindowWPF2;
|
||
/// <summary>
|
||
/// Halcon图像预览控件(只能用于预览)
|
||
/// </summary>
|
||
public HSmartWindowControlWPF HWindowWPF2
|
||
{
|
||
get { return hWindowWPF2; }
|
||
set
|
||
{
|
||
hWindowWPF2 = value;
|
||
RaisePropertyChanged("HWindowWPF2");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 图像对象
|
||
private HObject ho_Image;
|
||
/// <summary>
|
||
/// 相机图像
|
||
/// </summary>
|
||
public HObject Ho_Image
|
||
{
|
||
get { return ho_Image; }
|
||
set
|
||
{
|
||
ho_Image = value;
|
||
}
|
||
}
|
||
|
||
private HObject ho_ImageLocal;
|
||
/// <summary>
|
||
/// 本地图像
|
||
/// </summary>
|
||
public HObject Ho_ImageLocal
|
||
{
|
||
get { return ho_ImageLocal; }
|
||
set
|
||
{
|
||
ho_ImageLocal = value;
|
||
this.RaisePropertyChanged("Ho_ImageLocal");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 当前选中的产品区域模型
|
||
private V_RectangleModel selectModel;
|
||
/// <summary>
|
||
/// 当前选中的区域模型
|
||
/// </summary>
|
||
public V_RectangleModel SelectModel
|
||
{
|
||
get { return selectModel; }
|
||
set
|
||
{
|
||
selectModel = value;
|
||
|
||
PassagewayBrightness1 = value.PassagewayBrightness1;
|
||
PassagewayBrightness2 = value.PassagewayBrightness2;
|
||
PassagewayBrightness3 = value.PassagewayBrightness3;
|
||
PassagewayBrightness4 = value.PassagewayBrightness4;
|
||
|
||
this.RaisePropertyChanged("SelectModel");
|
||
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 各种方法
|
||
/// <summary>
|
||
/// 相机检查
|
||
/// </summary>
|
||
public DelegateCommand CamCheckCommand { get; set; }
|
||
/// <summary>
|
||
/// 相机重置
|
||
/// </summary>
|
||
public DelegateCommand CamResetCommand { get; set; }
|
||
/// <summary>
|
||
/// 停止连续采集
|
||
/// </summary>
|
||
public DelegateCommand StopCalibrationCommand { get; set; }
|
||
/// <summary>
|
||
/// 打开相机
|
||
/// </summary>
|
||
public DelegateCommand OpenCameraCommand { get; set; }
|
||
/// <summary>
|
||
/// 图像采集
|
||
/// </summary>
|
||
public DelegateCommand GetImageCommand { get; set; }
|
||
/// <summary>
|
||
/// 加载本地图像
|
||
/// </summary>
|
||
public DelegateCommand LoadingImageCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 相机校正
|
||
/// </summary>
|
||
public DelegateCommand CameraCorrectionCommand { get; set; }
|
||
/// <summary>
|
||
|
||
/// <summary>
|
||
/// 保存相机参数
|
||
/// </summary>
|
||
public DelegateCommand SaveCamPerCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// 定位模型建立设置
|
||
/// </summary>
|
||
public DelegateCommand LocationSettingCommand { get; set; }
|
||
/// <summary>
|
||
/// 定位测试
|
||
/// </summary>
|
||
public DelegateCommand LocationCheckCommand { get; set; }
|
||
|
||
/// <summary>
|
||
/// Roi形状选择
|
||
/// </summary>
|
||
public DelegateCommand RoiShapeSelectCommand { get; set; }
|
||
|
||
#endregion
|
||
|
||
#region 相机对象
|
||
private FeiYuCamere camera;
|
||
/// <summary>
|
||
/// 相机对象
|
||
/// </summary>
|
||
public FeiYuCamere Camera
|
||
{
|
||
get { return camera; }
|
||
set
|
||
{
|
||
camera = value;
|
||
this.RaisePropertyChanged("Camera");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 是否正在创建或编辑区域模型或ROI
|
||
/// <summary>
|
||
/// 是否正在创建或编辑区域模型或ROI
|
||
/// </summary>
|
||
public bool CreateModeling { get; set; }
|
||
#endregion
|
||
|
||
#region 光源通道集合
|
||
private List<string> passagewayLightList;
|
||
/// <summary>
|
||
/// 光源通道集合
|
||
/// </summary>
|
||
public List<string> PassagewayLightList
|
||
{
|
||
get { return passagewayLightList; }
|
||
set
|
||
{
|
||
passagewayLightList = value;
|
||
this.RaisePropertyChanged("PassagewayLightList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 光源通道
|
||
private string passagewayLight;
|
||
/// <summary>
|
||
/// 光源通道
|
||
/// </summary>
|
||
public string PassagewayLight
|
||
{
|
||
get { return passagewayLight; }
|
||
set
|
||
{
|
||
passagewayLight = value;
|
||
if (!string.IsNullOrEmpty(value))
|
||
{
|
||
switch (value)
|
||
{
|
||
case "SA":
|
||
Brightness = PassagewayBrightness1;
|
||
break;
|
||
case "SB":
|
||
Brightness = PassagewayBrightness2;
|
||
break;
|
||
case "SC":
|
||
Brightness = PassagewayBrightness3;
|
||
break;
|
||
case "SD":
|
||
Brightness = PassagewayBrightness4;
|
||
break;
|
||
}
|
||
|
||
}
|
||
this.RaisePropertyChanged("PassagewayLight");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 光源各通道亮度
|
||
/// <summary>
|
||
/// 光源通道1亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness1 { get; set; }
|
||
/// <summary>
|
||
/// 光源通道2亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness2 { get; set; }
|
||
/// <summary>
|
||
/// 光源通道3亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness3 { get; set; }
|
||
/// <summary>
|
||
/// 光源通道4亮度
|
||
/// </summary>
|
||
public long PassagewayBrightness4 { get; set; }
|
||
#endregion
|
||
|
||
#region 光源亮度
|
||
private long brightness;
|
||
/// <summary>
|
||
/// 光源亮度
|
||
/// </summary>
|
||
public long Brightness
|
||
{
|
||
get { return brightness; }
|
||
set
|
||
{
|
||
brightness = value;
|
||
|
||
try
|
||
{
|
||
if (value >= 0 && !string.IsNullOrEmpty(PassagewayLight))
|
||
{
|
||
// LightCOM.Send("SA" + string.Format("{0:d3}", value) + "#");
|
||
LightCOM.Send(PassagewayLight + string.Format("{0:d3}", value) + "#");
|
||
switch (PassagewayLight)
|
||
{
|
||
case "SA":
|
||
PassagewayBrightness1 = value;
|
||
break;
|
||
case "SB":
|
||
PassagewayBrightness2 = value;
|
||
break;
|
||
case "SC":
|
||
PassagewayBrightness3 = value;
|
||
break;
|
||
case "SD":
|
||
PassagewayBrightness4 = value;
|
||
break;
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
|
||
this.RaisePropertyChanged("Brightness");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 光源串口对象
|
||
private SerialCom lightCOM;
|
||
/// <summary>
|
||
/// 光源串口对象
|
||
/// </summary>
|
||
public SerialCom LightCOM
|
||
{
|
||
get { return lightCOM; }
|
||
set
|
||
{
|
||
lightCOM = value;
|
||
this.RaisePropertyChanged("LightCOM");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 图片保留天数集合
|
||
private List<int> retentionDaysImageList;
|
||
/// <summary>
|
||
/// 图片保留天数集合
|
||
/// </summary>
|
||
public List<int> RetentionDaysImageList
|
||
{
|
||
get { return retentionDaysImageList; }
|
||
set
|
||
{
|
||
retentionDaysImageList = value;
|
||
this.RaisePropertyChanged("RetentionDaysImageList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 特征识别系数集合
|
||
private List<double> coeList;
|
||
/// <summary>
|
||
/// 特征识别系数集合
|
||
/// </summary>
|
||
public List<double> CoeList
|
||
{
|
||
get { return coeList; }
|
||
set
|
||
{
|
||
coeList = value;
|
||
this.RaisePropertyChanged("CoeList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 构造函数
|
||
public HalconVisual(MachineModel machine, SerialCom sc, FeiYuCamere camere)
|
||
{
|
||
HWindowWPF2 = new HSmartWindowControlWPF();//视觉预览控件
|
||
HWindowWPF = new HWindowControlWPF(); //视觉编辑显示控件
|
||
MyWindow = new AOI();
|
||
MyWindow.DataContext = this;
|
||
SuperPrivilege = Visibility.Collapsed;
|
||
ControlShow = "0";
|
||
|
||
PassagewayLightList = new List<string>() { "SA", "SB", "SC", "SD" };
|
||
LightCOM = sc;
|
||
|
||
RetentionDaysImageList = new List<int>() { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 };
|
||
CoeList = new List<double>() { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 };
|
||
|
||
|
||
//HWindowWPF.HMouseWheel += HWindowWPF_HMouseWheel;
|
||
//HWindowWPF.HMouseDown += HWindowWPF_HMouseDown;
|
||
//HWindowWPF.HMouseUp += HWindowWPF_HMouseUp;
|
||
|
||
|
||
|
||
|
||
Camera = camere;//获取相机对象
|
||
Camera.eventProcessImage += ProcessHImage; // 注册halcon显示回调函数
|
||
Camera.resolvingPowerSet += SetResolvingPower; //注册分辨率设置事件
|
||
|
||
MachineObj = machine;
|
||
|
||
Ho_Image = new HObject();
|
||
HobjectList = new List<HObject>();
|
||
|
||
SweepCodeInitialize();
|
||
CalibrationInitialize();
|
||
InitializationFunctionEditing();
|
||
V_OcrVMInitialization();
|
||
MeasureInitialize();
|
||
InspectionFeaturesInitialization();
|
||
|
||
this.CamCheckCommand = new DelegateCommand();
|
||
this.CamCheckCommand.ExecuteAction = new Action<object>(CamCheck);
|
||
|
||
this.CamResetCommand = new DelegateCommand();
|
||
this.CamResetCommand.ExecuteAction = new Action<object>(CamReset);
|
||
|
||
this.StopCalibrationCommand = new DelegateCommand();
|
||
this.StopCalibrationCommand.ExecuteAction = new Action<object>(StopCalibration);
|
||
|
||
this.OpenCameraCommand = new DelegateCommand();
|
||
this.OpenCameraCommand.ExecuteAction = new Action<object>(OpenVideo);
|
||
|
||
this.GetImageCommand = new DelegateCommand();
|
||
this.GetImageCommand.ExecuteAction = new Action<object>(GetImage);
|
||
|
||
this.SaveCamPerCommand = new DelegateCommand();
|
||
this.SaveCamPerCommand.ExecuteAction = new Action<object>(SaveCamPer);
|
||
|
||
this.LoadingImageCommand = new DelegateCommand();
|
||
this.LoadingImageCommand.ExecuteAction = new Action<object>(LoadingImage);
|
||
|
||
//相机校正
|
||
this.CameraCorrectionCommand = new DelegateCommand();
|
||
this.CameraCorrectionCommand.ExecuteAction = new Action<object>(CameraCorrection);
|
||
|
||
this.LocationSettingCommand = new DelegateCommand();
|
||
this.LocationSettingCommand.ExecuteAction = new Action<object>(LocationSetting);
|
||
|
||
this.LocationCheckCommand = new DelegateCommand();
|
||
this.LocationCheckCommand.ExecuteAction = new Action<object>(LocationCheck);
|
||
|
||
this.RoiShapeSelectCommand = new DelegateCommand();
|
||
this.RoiShapeSelectCommand.ExecuteAction = new Action<object>(RoiShapeSelect);
|
||
|
||
|
||
}
|
||
|
||
private void RoiShapeSelect(object obj)
|
||
{
|
||
string str = obj.ToString();
|
||
DrawRoiShape = (DrawRoiEmn)Enum.Parse(typeof(DrawRoiEmn), str);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
/// <param name="WPFconttrol">Halcon显示控件</param>
|
||
/// <param name="machine">机种</param>
|
||
/// <param name="CameType">相机类型 0:第一个相机1:第二个相机</param>
|
||
/// <param name="sc">光源串口对象</param>
|
||
public HalconVisual(HWindowControlWPF WPFconttrol, MachineModel machine, int camType, SerialCom sc)
|
||
{
|
||
HWindowWPF = new HWindowControlWPF(); //初始化显示控件
|
||
MyWindow = new AOI();
|
||
// HWindowWPF = MyWindow.hsm;
|
||
MyWindow.DataContext = this;
|
||
ControlShow = "0";
|
||
|
||
PassagewayLightList = new List<string>() { "SA", "SB", "SC", "SD" };
|
||
LightCOM = sc;
|
||
|
||
RetentionDaysImageList = new List<int>() { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 };
|
||
CoeList = new List<double>() { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 };
|
||
|
||
|
||
HWindowWPF = WPFconttrol;
|
||
//HWindowWPF.HMouseWheel += HWindowWPF_HMouseWheel;
|
||
//HWindowWPF.HMouseDown += HWindowWPF_HMouseDown;
|
||
//HWindowWPF.HMouseUp += HWindowWPF_HMouseUp;
|
||
this.CameraType = camType;
|
||
MachineObj = machine;
|
||
|
||
Ho_Image = new HObject();
|
||
HobjectList = new List<HObject>();
|
||
|
||
SweepCodeInitialize();
|
||
CalibrationInitialize();
|
||
InitializationFunctionEditing();
|
||
V_OcrVMInitialization();
|
||
MeasureInitialize();
|
||
InspectionFeaturesInitialization();
|
||
|
||
this.CamCheckCommand = new DelegateCommand();
|
||
this.CamCheckCommand.ExecuteAction = new Action<object>(CamCheck);
|
||
|
||
this.CamResetCommand = new DelegateCommand();
|
||
this.CamResetCommand.ExecuteAction = new Action<object>(CamReset);
|
||
|
||
this.StopCalibrationCommand = new DelegateCommand();
|
||
this.StopCalibrationCommand.ExecuteAction = new Action<object>(StopCalibration);
|
||
|
||
this.OpenCameraCommand = new DelegateCommand();
|
||
this.OpenCameraCommand.ExecuteAction = new Action<object>(OpenVideo);
|
||
|
||
this.GetImageCommand = new DelegateCommand();
|
||
this.GetImageCommand.ExecuteAction = new Action<object>(GetImage);
|
||
|
||
this.SaveCamPerCommand = new DelegateCommand();
|
||
this.SaveCamPerCommand.ExecuteAction = new Action<object>(SaveCamPer);
|
||
|
||
this.LoadingImageCommand = new DelegateCommand();
|
||
this.LoadingImageCommand.ExecuteAction = new Action<object>(LoadingImage);
|
||
|
||
//相机校正
|
||
this.CameraCorrectionCommand = new DelegateCommand();
|
||
this.CameraCorrectionCommand.ExecuteAction = new Action<object>(CameraCorrection);
|
||
|
||
this.LocationSettingCommand = new DelegateCommand();
|
||
this.LocationSettingCommand.ExecuteAction = new Action<object>(LocationSetting);
|
||
|
||
this.LocationCheckCommand = new DelegateCommand();
|
||
this.LocationCheckCommand.ExecuteAction = new Action<object>(LocationCheck);
|
||
|
||
this.RoiShapeSelectCommand = new DelegateCommand();
|
||
this.RoiShapeSelectCommand.ExecuteAction = new Action<object>(RoiShapeSelect);
|
||
|
||
}
|
||
|
||
|
||
#region 定位设置
|
||
/// <summary>
|
||
/// 定位设置
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void LocationSetting(object obj)
|
||
{
|
||
if (SelectModel.ID <= 0)
|
||
{
|
||
if (SaveAll(SelectModel))
|
||
{
|
||
SelectModel = Vdal.GetRectangleModel(SelectModel.VeiID, SelectModel.AreaType);
|
||
if (SelectModel.ID > 0)
|
||
{
|
||
switch (SelectVEI.HandleType)
|
||
{
|
||
case 1:
|
||
break;
|
||
case 2:
|
||
GenerateFeaturesModel(SelectModel);
|
||
break;
|
||
case 3:
|
||
break;
|
||
case 4:
|
||
break;
|
||
case 5:
|
||
break;
|
||
case 6:
|
||
CreateJiaoDian(SelectVEI);
|
||
break;
|
||
case 7:
|
||
CreateCircleModel(SelectVEI);
|
||
break;
|
||
case 8:
|
||
CreateCircleModel(SelectVEI);
|
||
break;
|
||
case 9:
|
||
CreateRectangleModel(SelectModel);
|
||
break;
|
||
case 11:
|
||
|
||
CreateTwoCircleModel(SelectVEI);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
switch (SelectVEI.HandleType)
|
||
{
|
||
case 1:
|
||
break;
|
||
case 2:
|
||
GenerateFeaturesModel(SelectModel);
|
||
break;
|
||
case 3:
|
||
break;
|
||
case 4:
|
||
break;
|
||
case 5:
|
||
break;
|
||
case 6:
|
||
CreateJiaoDian(SelectVEI);
|
||
break;
|
||
case 7:
|
||
CreateCircleModel(SelectVEI);
|
||
break;
|
||
case 8:
|
||
CreateCircleModel(SelectVEI);
|
||
break;
|
||
case 9:
|
||
CreateRectangleModel(SelectModel);
|
||
break;
|
||
case 11:
|
||
|
||
CreateTwoCircleModel(SelectVEI);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 定位测试
|
||
/// <summary>
|
||
/// 定位测试
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
private void LocationCheck(object obj)
|
||
{
|
||
if (SelectModel.ID > 0)
|
||
{
|
||
switch (SelectVEI.HandleType)
|
||
{
|
||
case 1:
|
||
break;
|
||
case 2:
|
||
FeatureMatchingIng(SelectVEI);
|
||
break;
|
||
case 3:
|
||
break;
|
||
case 4:
|
||
break;
|
||
case 5:
|
||
break;
|
||
case 6:
|
||
FeatureMatchingJiaodian(SelectVEI);
|
||
break;
|
||
case 7:
|
||
FeatureMatchingCirCle(SelectModel);
|
||
break;
|
||
case 8:
|
||
FeatureMatchingCirCle2(SelectVEI);
|
||
break;
|
||
case 9:
|
||
FeatureMatchingRectangle2(SelectModel);
|
||
break;
|
||
case 11:
|
||
FeatureMatchinFindTwoCirCle(SelectVEI);
|
||
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("没有任何特征数据");
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
|
||
#region 鼠标按下
|
||
|
||
HTuple m_hRowB, m_hColB, m_hButton, m_hRowE, m_hColE;
|
||
/// <summary>
|
||
/// 鼠标按下
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public void HWindowWPF_HMouseDown(object sender, HMouseEventArgsWPF e)
|
||
{
|
||
|
||
if (CreateModeling || HobjectList.Count <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
HOperatorSet.SetCheck("~give_error");
|
||
HOperatorSet.GetMposition(HWindowWPF.HalconWindow, out m_hRowB, out m_hColB, out m_hButton);
|
||
|
||
}
|
||
catch
|
||
{
|
||
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 鼠标松开
|
||
/// <summary>
|
||
/// 鼠标松开
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public void HWindowWPF_HMouseUp(object sender, HMouseEventArgsWPF e)
|
||
{
|
||
if (CreateModeling || HobjectList.Count <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
HOperatorSet.SetCheck("~give_error");
|
||
HOperatorSet.GetMposition(HWindowWPF.HalconWindow, out m_hRowE, out m_hColE, out m_hButton);
|
||
|
||
HTuple row1, col1, row2, col2;
|
||
double dbRowMove, dbColMove;
|
||
double dbRowB, dbColB, dbRowE, dbColE;
|
||
dbRowB = m_hRowB;
|
||
dbRowE = m_hRowE;
|
||
dbColB = m_hColB;
|
||
dbColE = m_hColE;
|
||
dbRowMove = -dbRowE + dbRowB;
|
||
dbColMove = -dbColE + dbColB;
|
||
|
||
HOperatorSet.GetPart(HWindowWPF.HalconWindow, out row1, out col1, out row2, out col2);
|
||
HOperatorSet.SetPart(HWindowWPF.HalconWindow, row1 + dbRowMove, col1 + dbColMove, row2 + dbRowMove, col2 + dbColMove);
|
||
|
||
|
||
RefeshWindow();//刷新显示
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 显示控件滚动图片放缩小
|
||
/// <summary>
|
||
/// 显示控件滚动图片放缩小
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
public void HWindowWPF_HMouseWheel(object sender, HMouseEventArgsWPF e)
|
||
{
|
||
if (CreateModeling || HobjectList.Count <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
//double x = e.X;
|
||
//double y = e.Y;
|
||
double Zoom = 1.0;
|
||
double ZoomTrans = 1.0, ZoomOrg = 1.0, RowShif, ColShif;
|
||
HTuple Row0, Column0, Row00, Column00, Ht, Wt, r1, c1, r2, c2;
|
||
HTuple Row, Col, Button;
|
||
|
||
HOperatorSet.SetCheck("~give_error");
|
||
HOperatorSet.GetMposition(HWindowWPF.HalconWindow, out Row, out Col, out Button);
|
||
HOperatorSet.GetPart(HWindowWPF.HalconWindow, out Row0, out Column0, out Row00, out Column00);
|
||
|
||
if (e.Delta >= 0)
|
||
{
|
||
if (0 != Zoom && Zoom >= 32.0)
|
||
{
|
||
Zoom = 32.0;
|
||
}
|
||
else
|
||
{
|
||
Zoom = 1.0 + Zoom;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (0 != Zoom && Zoom <= (1.0 / 16))
|
||
{
|
||
Zoom = 1.0 / 16;
|
||
}
|
||
else
|
||
{
|
||
Zoom = Zoom / 2;
|
||
}
|
||
}
|
||
ZoomTrans = Zoom / ZoomOrg;
|
||
ZoomOrg = Zoom;
|
||
RowShif = 0;
|
||
ColShif = 0;
|
||
Ht = Row00 - Row0;
|
||
Wt = Column00 - Column0;
|
||
r1 = (Row0 + ((1 - (1.0 / ZoomTrans)) * (Row - Row0))) - (RowShif / ZoomTrans);
|
||
c1 = (Column0 + ((1 - (1.0 / ZoomTrans)) * (Col - Column0))) - (ColShif / ZoomTrans);
|
||
r2 = r1 + (Ht / ZoomTrans);
|
||
c2 = c1 + (Wt / ZoomTrans);
|
||
|
||
HOperatorSet.SetPart(HWindowWPF.HalconWindow, r1, c1, r2, c2);
|
||
|
||
RefeshWindow();//刷新显示
|
||
|
||
|
||
}
|
||
catch
|
||
{
|
||
RefeshWindow();//刷新显示
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 设置控件分辨率
|
||
|
||
/// <summary>
|
||
/// 十字架准星
|
||
/// </summary>
|
||
HObject ho_Cross;
|
||
/// <summary>
|
||
/// 设置控件分辨率
|
||
/// </summary>
|
||
/// <param name="re"></param>
|
||
public void SetResolvingPower(Rect re)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0) //检查窗口是否存在
|
||
{
|
||
//直接填充
|
||
//HWindowWPF.ImagePart = re;
|
||
//return;
|
||
|
||
#region 等比例显示
|
||
//等比例显示
|
||
int imgWidth, imgHeight, winRow, winCol, winWidth, winHeight, partWidth, partHeight;
|
||
try
|
||
{
|
||
imgWidth = (int)re.Width;
|
||
imgHeight = (int)re.Height;//image.GetImageSize(out imgWidth, out imgHeight);
|
||
HWindowWPF.HalconWindow.GetWindowExtents(out winRow, out winCol, out winWidth, out winHeight);
|
||
|
||
double ib = (double)imgWidth / imgHeight; //图像的长宽比
|
||
double wb = (double)winWidth / winHeight; //显示控件的长宽比
|
||
|
||
double x = 0, y = 0;
|
||
|
||
|
||
if (ib > 1)
|
||
{
|
||
if (imgWidth > winWidth && imgHeight > winHeight)
|
||
{
|
||
partWidth = wb < ib ? imgWidth : imgHeight * winWidth / winHeight;
|
||
|
||
partHeight = wb < ib ? imgWidth * winHeight / winWidth : imgHeight;
|
||
}
|
||
else if (imgWidth > winWidth)
|
||
{
|
||
partWidth = wb < ib ? imgWidth : imgHeight * winWidth / winHeight;
|
||
|
||
partHeight = wb < ib ? imgWidth * winHeight / winWidth : winHeight;
|
||
}
|
||
else if (imgHeight > winHeight)
|
||
{
|
||
partWidth = wb < ib ? imgWidth : imgHeight * winWidth / winHeight;
|
||
|
||
partHeight = wb < ib ? imgWidth * winHeight / imgWidth : imgHeight;
|
||
}
|
||
else
|
||
{
|
||
partWidth = wb < ib ? winWidth : imgHeight * winWidth / imgHeight;
|
||
|
||
partHeight = wb < ib ? winHeight : imgWidth * winHeight / imgWidth;
|
||
}
|
||
|
||
//partWidth = imgWidth;
|
||
//partHeight = ib < 1 ? imgHeight : imgWidth * winHeight / winWidth;
|
||
}
|
||
else
|
||
{
|
||
if (imgWidth > winWidth && imgHeight > winHeight)
|
||
{
|
||
partWidth = wb < ib ? imgWidth : imgHeight * winWidth / winHeight;
|
||
partHeight = wb < ib ? imgWidth * winHeight / winWidth : imgHeight;
|
||
}
|
||
else if (imgWidth > winWidth)
|
||
{
|
||
partWidth = wb < ib ? imgHeight * winWidth / imgHeight : imgWidth;
|
||
partHeight = wb < ib ? imgWidth * winHeight / imgWidth : winHeight;
|
||
}
|
||
else if (imgHeight > winHeight)
|
||
{
|
||
partWidth = wb < ib ? winWidth : imgHeight * winWidth / winHeight;
|
||
partHeight = wb < ib ? imgWidth * winHeight / imgWidth : imgHeight;
|
||
}
|
||
else
|
||
{
|
||
partWidth = wb < ib ? imgHeight * winWidth / imgHeight : winWidth;
|
||
partHeight = wb < ib ? imgWidth * winHeight / imgWidth : winHeight;
|
||
}
|
||
|
||
|
||
//partWidth = imgHeight * winWidth / winHeight;
|
||
//partHeight = imgHeight;
|
||
|
||
}
|
||
|
||
|
||
x = (imgWidth - partWidth) / 2;
|
||
x = x > 0 ? 0 : x;
|
||
y = (imgHeight - partHeight) / 2;
|
||
y = y > 0 ? 0 : y;
|
||
|
||
|
||
re.Width = partWidth;
|
||
re.Height = partHeight;
|
||
re.X = x;
|
||
re.Y = y;
|
||
HWindowWPF.ImagePart = re;
|
||
//HWindowWPF.HalconWindow.SetPart(100, 0, partHeight - 1, partWidth - 1);
|
||
// window.DispImage(image);
|
||
|
||
//刷新十字准星
|
||
// HOperatorSet.GenCrossContourXld(out ho_Cross, re.Height / 2, re.Width / 2, 500, 0);
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, imgHeight / 2, imgWidth / 2, 500, 0);
|
||
}
|
||
catch (HalconException hEx)
|
||
{
|
||
ShowText(hEx.Message, "red");
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 相机检测
|
||
/// <summary>
|
||
/// 相机检测
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void CamCheck(object obj)
|
||
{
|
||
Camera.GetCamNameList();
|
||
}
|
||
#endregion
|
||
|
||
#region 相机重置
|
||
/// <summary>
|
||
/// 相机重置
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void CamReset(object obj)
|
||
{
|
||
Camera.CloseCam();
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 保存相机参数
|
||
/// <summary>
|
||
/// 保存相机参数
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void SaveCamPer(object obj)
|
||
{
|
||
if (Camera.ID <= 0)
|
||
{
|
||
Camera.ErrorMessage = Vdal.AddCamera(Camera) > 0 ? "相机参数添加成功" : "相机参数添加失败";
|
||
}
|
||
else
|
||
{
|
||
Camera.ErrorMessage = Vdal.UpdateCamera(Camera) > 0 ? "相机参数更新成功" : "相机参数更新失败";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 开启视屏
|
||
/// <summary>
|
||
/// 是否是连续取图模式
|
||
/// </summary>
|
||
bool ContinuousAcquisition { get; set; }
|
||
/// <summary>
|
||
/// 开启视屏
|
||
/// </summary>
|
||
public void OpenVideo(object obj)
|
||
{
|
||
if (Camera == null)
|
||
{
|
||
return;
|
||
}
|
||
Buzhixing = true;
|
||
ContinuousAcquisition = Camera.StartGrabbing();
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region 停止连续采集
|
||
/// <summary>
|
||
/// 停止连续采集
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void StopCalibration(object obj)
|
||
{
|
||
Camera.StopGrabbing();
|
||
ContinuousAcquisition = false;
|
||
}
|
||
#endregion
|
||
|
||
#region 加载本地图像
|
||
|
||
private string imgPath;
|
||
/// <summary>
|
||
/// 本地图片地址
|
||
/// </summary>
|
||
public string ImgPath
|
||
{
|
||
get { return imgPath; }
|
||
set
|
||
{
|
||
imgPath = value;
|
||
this.RaisePropertyChanged("ImgPath");
|
||
}
|
||
}
|
||
|
||
HObject ho_bendiImage = new HObject();
|
||
|
||
/// <summary>
|
||
/// 加载本地图像
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void LoadingImage(object obj)
|
||
{
|
||
HTuple hv_Width, hv_Height;
|
||
OpenFileDialog openFile = new OpenFileDialog();
|
||
openFile.Filter = "图像文件(*.tif*.tiff*.bmp*.jpg*.jpeg*.jp2*.png*.pcx*.pgm*.ppm*.pbm*.xwd*.ima*.hobj)|*.tif;*.tiff;*.bmp;*.jpg;*.jpeg;*.jp2;*.png;*.pcx;*.pgm;*.ppm;*.pbm;*.xwd;*.ima;*.hobj|所有文件(*.*)|*.*";
|
||
try
|
||
{
|
||
if (openFile.ShowDialog() == true)
|
||
{
|
||
ImgPath = openFile.FileName;
|
||
ho_bendiImage.Dispose();
|
||
HOperatorSet.ReadImage(out ho_bendiImage, ImgPath);
|
||
//HObject imga = new HObject();
|
||
// HOperatorSet.RotateImage(ho_bendiImage, out ho_bendiImage, Camera.RotateAngle, "constant");
|
||
HOperatorSet.GetImageSize(ho_bendiImage, out hv_Width, out hv_Height); //获取分辨率
|
||
SetResolvingPower(new System.Windows.Rect(0, 0, hv_Width, hv_Height));//设置图像像是控件分辨率
|
||
|
||
ClearWindowAndData();
|
||
ShowObj(ho_bendiImage);
|
||
ShowText("Image Size:" + hv_Height.ToString() + "*" + hv_Width.ToString(), "green");
|
||
Ho_ImageLocal = ho_bendiImage;
|
||
|
||
EnableLocalImage = true;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
MessageBox.Show("本地图片打开失败");
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 是否启用本地图片
|
||
private bool enableLocalImage;
|
||
/// <summary>
|
||
/// 是否启用本地图片
|
||
/// </summary>
|
||
public bool EnableLocalImage
|
||
{
|
||
get { return enableLocalImage; }
|
||
set
|
||
{
|
||
enableLocalImage = value;
|
||
if (Ho_ImageLocal != null && value)
|
||
{
|
||
Ho_Image = Ho_ImageLocal;
|
||
}
|
||
this.RaisePropertyChanged("EnableLocalImage");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 获取图片
|
||
/// <summary>
|
||
/// 获取单张图片
|
||
/// </summary>
|
||
public void GetImage(object obj)
|
||
{
|
||
|
||
ContinuousAcquisition = false;
|
||
EnableLocalImage = false;
|
||
if (!GetImage(null))
|
||
{
|
||
return;
|
||
}
|
||
|
||
HTuple hv_Width, hv_Height;
|
||
HOperatorSet.GetImageSize(Ho_Image, out hv_Width, out hv_Height); //获取分辨率
|
||
ShowText("Image Size:" + hv_Height.ToString() + "*" + hv_Width.ToString(), "green");
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取图像
|
||
/// </summary>
|
||
/// <param name="RM">RM对象用于设置光源</param>
|
||
/// <returns></returns>
|
||
public bool GetImage(V_RectangleModel RM)
|
||
{
|
||
//1,获取图像
|
||
if (EnableLocalImage)
|
||
{
|
||
Ho_Image = Ho_ImageLocal;
|
||
}
|
||
else
|
||
{
|
||
//if (RM != null)
|
||
//{
|
||
// SetLight(RM);//设置光源亮度
|
||
//}
|
||
Buzhixing = true;
|
||
ClearWindowAndData();
|
||
Ho_Image = Camera.GrabOne();
|
||
}
|
||
|
||
if (!HobjectIsNull(Ho_Image))
|
||
{
|
||
ShowObj(Ho_Image);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
ShowText("获取图像失败", "red");
|
||
return false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 获取图像
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool GetImage()
|
||
{
|
||
|
||
Camera.SetExposureTime(Camera.ExposureTime);//设置曝光 防止设置不进去的情况
|
||
//1,获取图像
|
||
if (EnableLocalImage)
|
||
{
|
||
Ho_Image = Ho_ImageLocal;
|
||
}
|
||
else
|
||
{
|
||
Buzhixing = true;
|
||
ClearWindowAndData();
|
||
Ho_Image = Camera.GrabOne();
|
||
}
|
||
|
||
if (!HobjectIsNull(Ho_Image))
|
||
{
|
||
ShowObj(Ho_Image);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
ShowText("获取图像失败", "red");
|
||
return false;
|
||
}
|
||
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 判断Hobject是否为空
|
||
/// <summary>
|
||
/// 判断Hobject是否为空
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
/// <returns></returns>
|
||
public bool HobjectIsNull(HObject obj)
|
||
{
|
||
bool bl = false;
|
||
try
|
||
{
|
||
if (obj != null)
|
||
{
|
||
HObject ho_temp;
|
||
HTuple hv_temp;
|
||
|
||
//IsInitialized只能用来判断图像有无初始化,不能判断图像空不空或有没有
|
||
if (!obj.IsInitialized())
|
||
{
|
||
bl = true;
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.GenEmptyObj(out ho_temp);
|
||
HOperatorSet.TestEqualObj(obj, ho_temp, out hv_temp);
|
||
if (hv_temp == 1)
|
||
{
|
||
bl = true;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
bl = true;
|
||
}
|
||
return bl;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return bl;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 绘制区域
|
||
/// <summary>
|
||
/// 绘制区域
|
||
/// </summary>
|
||
public V_RectangleModel DrawArea(HObject imageTemp, V_RectangleModel rm)
|
||
{
|
||
try
|
||
{
|
||
HObject ho_Rectangle;
|
||
HTuple hv_Row1 = null, hv_Column1 = null, hv_Row2 = null, hv_Column2 = null;
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle);
|
||
|
||
#region 1、图像准备
|
||
|
||
//显示图片
|
||
ShowObj(imageTemp);
|
||
|
||
ShowText("图像准备完毕,请绘制Mark范围区域", "green");
|
||
#endregion
|
||
|
||
#region 2、绘制模型区域
|
||
SetColored("blue");
|
||
//画笔设为边缘(边框)
|
||
SetDraw("margin");
|
||
//设置边框的粗细为3
|
||
HOperatorSet.SetLineWidth(HWindowWPF.HalconWindow, 3);
|
||
|
||
//画一个矩形 获取起点坐标和终点坐标
|
||
HOperatorSet.DrawRectangle1(HWindowWPF.HalconWindow, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);
|
||
|
||
//获取矩形区域模型
|
||
ho_Rectangle.Dispose();
|
||
HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
|
||
|
||
//显示图片
|
||
ShowObj(imageTemp);
|
||
//显示矩形区域
|
||
ShowObj(ho_Rectangle, "green");
|
||
|
||
#endregion
|
||
|
||
#region 3、获取模型信息
|
||
rm.Point_Row1 = hv_Row1;
|
||
rm.Point_Column1 = hv_Column1;
|
||
rm.Point_Row2 = hv_Row2;
|
||
rm.Point_Column2 = hv_Column2;
|
||
#endregion
|
||
|
||
ho_Rectangle.Dispose();
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show(ex.Message);
|
||
}
|
||
return rm;
|
||
}
|
||
#endregion
|
||
|
||
#region 绘制ROI
|
||
private DrawRoiEmn drawRoiShape;
|
||
/// <summary>
|
||
/// 绘制的ROI形状
|
||
/// </summary>
|
||
public DrawRoiEmn DrawRoiShape
|
||
{
|
||
get { return drawRoiShape; }
|
||
set
|
||
{
|
||
drawRoiShape = value;
|
||
this.RaisePropertyChanged("DrawRoiShape");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绘制ROI
|
||
/// </summary>
|
||
/// <param name="roi"></param>
|
||
/// <returns></returns>
|
||
public V_ROI DrawROI(V_ROI roi)
|
||
{
|
||
HObject ho_Rectangle;
|
||
HTuple hv_Row = null, hv_Column = null, hv_Radius = null, hv_Phi = null, hv_Length1 = null, hv_Length2 = null;
|
||
HTuple hv_Row1 = null, hv_Column1 = null, hv_Row2 = null, hv_Column2 = null;
|
||
|
||
|
||
ShowText("图像准备完毕,请绘制ROI区域", "green");
|
||
|
||
#region 2、绘制模型区域
|
||
//SetColored("blue");
|
||
HOperatorSet.SetColor(HWindowWPF.HalconWindow, "blue");
|
||
//画笔设为边缘(边框)
|
||
SetDraw("margin");
|
||
// HOperatorSet.SetDraw(HWindowWPF.HalconWindow, "margin");
|
||
//设置边框的粗细为3
|
||
HOperatorSet.SetLineWidth(HWindowWPF.HalconWindow, 1);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle);
|
||
switch (DrawRoiShape)
|
||
{
|
||
case DrawRoiEmn.C:
|
||
//画圆形
|
||
HOperatorSet.DrawCircle(HWindowWPF.HalconID, out hv_Row, out hv_Column, out hv_Radius);
|
||
HOperatorSet.GenCircle(out ho_Rectangle, hv_Row, hv_Column, hv_Radius);
|
||
|
||
roi.hv_Row = hv_Row;
|
||
roi.hv_Column = hv_Column;
|
||
roi.hv_Radius = hv_Radius;
|
||
roi.ho_OutlineROI = ho_Rectangle;
|
||
break;
|
||
case DrawRoiEmn.R1:
|
||
//画一个矩形 获取起点坐标和终点坐标
|
||
HOperatorSet.DrawRectangle1(HWindowWPF.HalconWindow, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);
|
||
//获取矩形区域模型
|
||
//ho_Rectangle.Dispose();
|
||
HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
|
||
|
||
roi.hv_Row = hv_Row1;
|
||
roi.hv_Column = hv_Column1;
|
||
roi.hv_Row1 = hv_Row2;
|
||
roi.hv_Column1 = hv_Column2;
|
||
roi.ho_OutlineROI = ho_Rectangle;
|
||
break;
|
||
case DrawRoiEmn.R2:
|
||
HOperatorSet.DrawRectangle2(HWindowWPF.HalconWindow, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2);
|
||
HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2);
|
||
|
||
roi.hv_Row = hv_Row;
|
||
roi.hv_Column = hv_Column;
|
||
roi.hv_Phi = hv_Phi;
|
||
roi.hv_length1 = hv_Length1;
|
||
roi.hv_length2 = hv_Length2;
|
||
roi.ho_OutlineROI = ho_Rectangle;
|
||
break;
|
||
}
|
||
|
||
roi.RoiShape = DrawRoiShape;
|
||
//显示ROI区域
|
||
ShowObj(ho_Rectangle, "green");
|
||
|
||
#endregion
|
||
|
||
return roi;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绘制ROI 选取特征专用
|
||
/// </summary>
|
||
/// <param name="roi"></param>
|
||
/// <returns></returns>
|
||
public bool DrawROI(V_RectangleModel RM)
|
||
{
|
||
bool bl = false;
|
||
try
|
||
{
|
||
|
||
HObject ho_Rectangle, ho_region_removeds;
|
||
HTuple hv_Row = null, hv_Column = null, hv_Radius = null, hv_Phi = null, hv_Length1 = null, hv_Length2 = null;
|
||
HTuple hv_Row1 = null, hv_Column1 = null, hv_Row2 = null, hv_Column2 = null;
|
||
HTuple hv_Button = null;
|
||
|
||
ShowText("请绘制ROI!单个ROI绘制完成单击右键后,继续绘制单击左键,结束单击右键", "green");
|
||
|
||
#region 2、绘制模型区域
|
||
//SetColored("blue");
|
||
SetColored("blue");
|
||
// HOperatorSet.SetColor(HWindowWPF.HalconWindow, "blue");
|
||
//画笔设为边缘(边框)
|
||
SetDraw("margin");
|
||
// HOperatorSet.SetDraw(HWindowWPF.HalconWindow, "margin");
|
||
//设置边框的粗细为3
|
||
HOperatorSet.SetLineWidth(HWindowWPF.HalconWindow, 1);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle);
|
||
HOperatorSet.GenEmptyObj(out ho_region_removeds);
|
||
hv_Button = 1;
|
||
while (hv_Button == 1)
|
||
{
|
||
SetColored("blue");
|
||
switch (DrawRoiShape)
|
||
{
|
||
case DrawRoiEmn.C:
|
||
//画圆形
|
||
HOperatorSet.DrawCircle(HWindowWPF.HalconID, out hv_Row, out hv_Column, out hv_Radius);
|
||
HOperatorSet.GenCircle(out ho_Rectangle, hv_Row, hv_Column, hv_Radius);
|
||
|
||
RM.MyROI.hv_Row = hv_Row;
|
||
RM.MyROI.hv_Column = hv_Column;
|
||
RM.MyROI.hv_Radius = hv_Radius;
|
||
RM.MyROI.ho_OutlineROI = ho_Rectangle;
|
||
break;
|
||
case DrawRoiEmn.R1:
|
||
//画一个矩形 获取起点坐标和终点坐标
|
||
HOperatorSet.DrawRectangle1(HWindowWPF.HalconWindow, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);
|
||
//获取矩形区域模型
|
||
//ho_Rectangle.Dispose();
|
||
HOperatorSet.GenRectangle1(out ho_Rectangle, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
|
||
|
||
RM.MyROI.hv_Row = hv_Row1;
|
||
RM.MyROI.hv_Column = hv_Column1;
|
||
RM.MyROI.hv_Row1 = hv_Row2;
|
||
RM.MyROI.hv_Column1 = hv_Column2;
|
||
RM.MyROI.ho_OutlineROI = ho_Rectangle;
|
||
break;
|
||
case DrawRoiEmn.R2:
|
||
HOperatorSet.DrawRectangle2(HWindowWPF.HalconWindow, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2);
|
||
HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2);
|
||
|
||
RM.MyROI.hv_Row = hv_Row;
|
||
RM.MyROI.hv_Column = hv_Column;
|
||
RM.MyROI.hv_Phi = hv_Phi;
|
||
RM.MyROI.hv_length1 = hv_Length1;
|
||
RM.MyROI.hv_length2 = hv_Length2;
|
||
RM.MyROI.ho_OutlineROI = ho_Rectangle;
|
||
break;
|
||
}
|
||
|
||
HOperatorSet.Union2(ho_region_removeds, ho_Rectangle, out ho_region_removeds);
|
||
//显示ROI区域
|
||
ShowObj(ho_Rectangle, "green");
|
||
//等待鼠标按下 1:左键 4:右键
|
||
HOperatorSet.GetMbutton(HWindowWPF.HalconWindow, out hv_Row, out hv_Column, out hv_Button);
|
||
|
||
|
||
}
|
||
RM.MyROI.RoiShape = DrawRoiShape;
|
||
RM.MyROI.ho_OutlineROI = ho_region_removeds;
|
||
// HOperatorSet.Difference(RM.ho_RectangleModel, ho_region_removeds, out RM.MyROI.ho_OutlineROI);
|
||
ShowObj(Ho_Image);
|
||
ShowObj(RM.ho_RectangleModel, "blue");
|
||
//显示ROI区域
|
||
ShowObj(RM.MyROI.ho_OutlineROI, "green");
|
||
#endregion
|
||
|
||
bl = true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowObj(Ho_Image);
|
||
ShowText("ROI绘制错误" + ex, "red", 30);
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 相机校正
|
||
/// <summary>
|
||
/// 相机校正中
|
||
/// </summary>
|
||
public bool CameraCorrectioning { get; set; }
|
||
|
||
/// <summary>
|
||
/// 相机校正
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public void CameraCorrection(object obj)
|
||
{
|
||
CameraCorrectioning = true;
|
||
}
|
||
#endregion
|
||
|
||
#region 创建角点模型
|
||
|
||
/// <summary>
|
||
/// 创建角点模型
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public void CreateJiaoDian(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
var lastExposureTime = Camera.ExposureTime;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
var RM = VEI.MyRectangleModel;
|
||
if (CreateModeling)
|
||
{
|
||
MyMessageBox.Show("当前已处于编辑状态,请完成之前的所有操作");
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要编辑模型吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
HObject ho_Line1, ho_Line2;
|
||
HTuple hv_Row1 = null, hv_Column1 = null, hv_Row2 = null, hv_Column2 = null;
|
||
HTuple hv_Row11 = null, hv_Column11 = null, hv_Row22 = null, hv_Column22 = null;
|
||
HTuple hv_Rowex, hv_Columnex, hv_Angle, hv_Angle1;
|
||
//1,获取图像
|
||
if (!GetImage())
|
||
{
|
||
return;
|
||
}
|
||
try
|
||
{
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
HObject ho_ImageScaled;
|
||
// HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, 1.90299, -230);
|
||
HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
Ho_Image = ho_ImageScaled;
|
||
}
|
||
|
||
ShowText("请绘制第一条线", "green");
|
||
HOperatorSet.DrawLine(HWindowWPF.HalconID, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);
|
||
HOperatorSet.GenRegionLine(out ho_Line1, hv_Row1, hv_Column1, hv_Row2, hv_Column2);
|
||
|
||
//显示ROI区域
|
||
ShowObj(Ho_Image);
|
||
ShowObj(ho_Line1, "green");
|
||
|
||
|
||
|
||
ShowText("请绘制第二条线", "green");
|
||
HOperatorSet.DrawLine(HWindowWPF.HalconID, out hv_Row11, out hv_Column11, out hv_Row22, out hv_Column22);
|
||
HOperatorSet.GenRegionLine(out ho_Line2, hv_Row11, hv_Column11, hv_Row22, hv_Column22);
|
||
|
||
//显示ROI区域
|
||
ShowObj(Ho_Image);
|
||
//ShowObj(ho_Line1, "green");
|
||
//ShowObj(ho_Line2, "green");
|
||
if (RM.MyCorner == null)
|
||
{
|
||
|
||
RM.MyCorner = new V_CornerPoint();
|
||
}
|
||
|
||
RM.MyCorner.hv_Row1 = hv_Row1;
|
||
RM.MyCorner.hv_Column1 = hv_Column1;
|
||
RM.MyCorner.hv_Row2 = hv_Row2;
|
||
RM.MyCorner.hv_Column2 = hv_Column2;
|
||
RM.MyCorner.hv_Row11 = hv_Row11;
|
||
RM.MyCorner.hv_Column11 = hv_Column11;
|
||
RM.MyCorner.hv_Row22 = hv_Row22;
|
||
RM.MyCorner.hv_Column22 = hv_Column22;
|
||
|
||
|
||
FindPoint(Ho_Image, RM.MyCorner, out hv_Rowex, out hv_Columnex, out hv_Angle, out hv_Angle1);
|
||
if (VEI.UpdateRef)
|
||
{
|
||
if (MyMessageBox.Show("更新参考吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
|
||
{
|
||
|
||
RM.MyROI.ModelFeaturePiont.hv_RefRow = hv_Rowex;
|
||
RM.MyROI.ModelFeaturePiont.hv_RefColumn = hv_Columnex;
|
||
RM.MyROI.ModelFeaturePiont.AngleU = hv_Angle.TupleDeg();
|
||
MyMessageBox.Show("更新参考成功");
|
||
|
||
}
|
||
}
|
||
|
||
|
||
|
||
Vdal.UpdateRectangleModel(RM);//保存参数
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 创建找矩形模型
|
||
|
||
/// <summary>
|
||
/// 创建找矩形模型
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public void CreateRectangleModel(V_RectangleModel RM)
|
||
{
|
||
if (CreateModeling)
|
||
{
|
||
MyMessageBox.Show("当前已处于编辑状态,请完成之前的所有操作");
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要编辑模型吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
HTuple hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Angle = new HTuple();
|
||
HTuple hv_Score = new HTuple(), hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple();
|
||
|
||
|
||
HObject ho_ModelRegion;
|
||
HObject ho_ModelContours, ho_TransContours;
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ModelRegion);
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ModelContours);
|
||
HOperatorSet.GenEmptyObj(out ho_TransContours);
|
||
|
||
//1,获取图像
|
||
if (!GetImage())
|
||
{
|
||
return;
|
||
}
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
//RM.MyROI.ShapeA_Min = 10;
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
HObject ho_ImageScaled;
|
||
// HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, 1.90299, -230);
|
||
HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
Ho_Image = ho_ImageScaled;
|
||
}
|
||
ShowObj(Ho_Image);
|
||
|
||
|
||
|
||
//去畸变
|
||
//DeDistortion();
|
||
|
||
CreateModeling = true;
|
||
//1,绘制区域模型
|
||
DrawArea(Ho_Image, RM);
|
||
RM.Instantiation();
|
||
|
||
//2,绘制ROI
|
||
DrawROI(RM);
|
||
//3、寻找ROI特征
|
||
SetDraw("fill");
|
||
// HOperatorSet.SetRgba(HWindowWPF2.HalconWindow, 255, 0, 0, 100); //设置后mask将显示为透明的红色,第四个参数控制透明度,范围:0~255
|
||
|
||
if (!FeatureMatchingRectangle2(RM))
|
||
{
|
||
MyMessageBox.Show("未能找到明显特征区域");
|
||
CreateModeling = false;
|
||
return;
|
||
}
|
||
|
||
if (MessageDialogResult.Affirmative == MyMessageBox.Show("模板设置完成是否保存?", "提示", MessageDialogStyle.AffirmativeAndNegative))
|
||
{
|
||
if (!EnableLocalImage)
|
||
{
|
||
RM.PassagewayBrightness1 = this.PassagewayBrightness1;
|
||
RM.PassagewayBrightness2 = this.PassagewayBrightness2;
|
||
RM.PassagewayBrightness3 = this.PassagewayBrightness3;
|
||
RM.PassagewayBrightness4 = this.PassagewayBrightness4;
|
||
}
|
||
if (SelectVEI.UpdateRef)
|
||
{
|
||
RM.MyROI.ModelFeaturePiont.hv_RefRow = CurrPixPoint.X;
|
||
RM.MyROI.ModelFeaturePiont.hv_RefColumn = CurrPixPoint.Y;
|
||
RM.MyROI.ModelFeaturePiont.AngleU = CurrPixPoint.Angle;
|
||
}
|
||
|
||
RM.Instantiation();
|
||
RM.MyROI.Initialize();
|
||
|
||
if (SaveAll(RM))
|
||
{
|
||
//string filePath = @"Image/" + RM.MyROI.HelpFileName + ".bmp"; //模板图片路径
|
||
//HOperatorSet.WriteImage(Ho_Image, "bmp", 0, filePath); //保存模板图片
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
CreateModeling = false;
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 创建找圆模型
|
||
|
||
/// <summary>
|
||
/// 创建找圆模型
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public void CreateCircleModel(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
var lastExposureTime = Camera.ExposureTime;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
var RM = VEI.MyRectangleModel;
|
||
if (CreateModeling)
|
||
{
|
||
MyMessageBox.Show("当前已处于编辑状态,请完成之前的所有操作");
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要编辑模型吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
HTuple hv_Parameter;
|
||
HObject ho_ImageReduced, ho_ImageScaled;
|
||
|
||
//1,获取图像
|
||
if (!GetImage())
|
||
{
|
||
return;
|
||
}
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
//if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
//{
|
||
// HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
// HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
// HOperatorSet.Rgb1ToGray(Ho_Image, out HObject ho_GrayImage);
|
||
// HOperatorSet.ScaleImage(ho_GrayImage, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
|
||
//}
|
||
//else
|
||
//{
|
||
// ho_ImageScaled = Ho_Image.Clone();
|
||
//}
|
||
|
||
ho_ImageScaled = Ho_Image.Clone();
|
||
ShowObj(Ho_Image);
|
||
|
||
|
||
|
||
//去畸变
|
||
//DeDistortion();
|
||
|
||
CreateModeling = true;
|
||
//1,绘制区域模型
|
||
DrawArea(Ho_Image, RM);
|
||
RM.Instantiation();
|
||
|
||
//2,绘制ROI
|
||
DrawROI(RM);
|
||
//3、寻找ROI特征
|
||
SetDraw("fill");
|
||
//截取矩形选框中的图像
|
||
HOperatorSet.ReduceDomain(ho_ImageScaled, RM.ho_RectangleModel, out ho_ImageReduced);
|
||
// HOperatorSet.SetRgba(HWindowWPF2.HalconWindow, 255, 0, 0, 100); //设置后mask将显示为透明的红色,第四个参数控制透明度,范围:0~255
|
||
bool bb = false;
|
||
List<V_Piont> PointList = new List<V_Piont>();
|
||
if (SelectVEI.HandleType == 7)
|
||
{
|
||
bb = FindCircle(ho_ImageScaled, RM, out PointList);
|
||
}
|
||
else
|
||
{
|
||
bb = FindCircle2(ho_ImageReduced, RM, out PointList);
|
||
}
|
||
if (!bb)
|
||
{
|
||
MyMessageBox.Show("未能找到明显特征区域");
|
||
CreateModeling = false;
|
||
return;
|
||
}
|
||
|
||
if (MessageDialogResult.Affirmative == MyMessageBox.Show("模板设置完成是否保存?", "提示", MessageDialogStyle.AffirmativeAndNegative))
|
||
{
|
||
if (!EnableLocalImage)
|
||
{
|
||
RM.PassagewayBrightness1 = this.PassagewayBrightness1;
|
||
RM.PassagewayBrightness2 = this.PassagewayBrightness2;
|
||
RM.PassagewayBrightness3 = this.PassagewayBrightness3;
|
||
RM.PassagewayBrightness4 = this.PassagewayBrightness4;
|
||
}
|
||
|
||
if (PointList != null && PointList.Count >= 0)
|
||
{
|
||
try
|
||
{
|
||
if (VEI.UpdateRef)
|
||
{
|
||
RM.MyROI.ModelFeaturePiont.hv_RefRow = PointList[0].hv_RefRow;
|
||
RM.MyROI.ModelFeaturePiont.hv_RefColumn = PointList[0].hv_RefColumn;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
|
||
}
|
||
|
||
//RM.MyROI.ModelFeaturePiont.hv_RefRadius = PointList[2];
|
||
//RM.MyROI.ModelFeaturePiont.AngleU = CurrPixPoint.Angle;
|
||
|
||
RM.LocateList = PointList;
|
||
|
||
}
|
||
|
||
RM.Instantiation();
|
||
RM.MyROI.Initialize();
|
||
|
||
if (!SaveAll(RM))
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
CreateModeling = false;
|
||
|
||
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 建立特征模板
|
||
/// <summary>
|
||
/// 建立特征模板
|
||
/// </summary>
|
||
/// <param name="CP"></param>
|
||
public void GenerateFeaturesModel(V_RectangleModel RM)
|
||
{
|
||
|
||
if (CreateModeling)
|
||
{
|
||
MyMessageBox.Show("当前已处于编辑状态,请完成之前的所有操作");
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要编辑模型吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
HTuple hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Angle = new HTuple();
|
||
HTuple hv_Score = new HTuple(), hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple();
|
||
|
||
|
||
HObject ho_ModelRegion;
|
||
HObject ho_ModelContours, ho_TransContours;
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ModelRegion);
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ModelContours);
|
||
HOperatorSet.GenEmptyObj(out ho_TransContours);
|
||
|
||
//1,获取图像
|
||
if (!GetImage())
|
||
{
|
||
return;
|
||
}
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
//RM.MyROI.ShapeA_Min = 10;
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
HObject ho_ImageScaled;
|
||
// HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, 1.90299, -230);
|
||
HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
Ho_Image = ho_ImageScaled;
|
||
}
|
||
ShowObj(Ho_Image);
|
||
|
||
|
||
|
||
//去畸变
|
||
//DeDistortion();
|
||
|
||
CreateModeling = true;
|
||
//1,绘制区域模型
|
||
V_RectangleModel rm = new V_RectangleModel();
|
||
rm = DrawArea(Ho_Image, rm);
|
||
rm.Instantiation();
|
||
|
||
//2,绘制ROI
|
||
rm.MyROI = new V_ROI();
|
||
DrawROI(rm);
|
||
//3、寻找ROI特征
|
||
SetDraw("fill");
|
||
// HOperatorSet.SetRgba(HWindowWPF2.HalconWindow, 255, 0, 0, 100); //设置后mask将显示为透明的红色,第四个参数控制透明度,范围:0~255
|
||
ho_TransContours.Dispose();
|
||
ho_TransContours = ModelPerReduction(rm);
|
||
ShowObj(ho_TransContours);
|
||
|
||
if (ho_TransContours == null)
|
||
{
|
||
MyMessageBox.Show("未能找到明显特征区域");
|
||
CreateModeling = false;
|
||
return;
|
||
}
|
||
|
||
if (MessageDialogResult.Affirmative == MyMessageBox.Show("模板设置完成是否保存?", "提示", MessageDialogStyle.AffirmativeAndNegative))
|
||
{
|
||
RM.Point_Row1 = rm.Point_Row1;
|
||
RM.Point_Row2 = rm.Point_Row2;
|
||
RM.Point_Column1 = rm.Point_Column1;
|
||
RM.Point_Column2 = rm.Point_Column2;
|
||
|
||
if (!EnableLocalImage)
|
||
{
|
||
RM.PassagewayBrightness1 = this.PassagewayBrightness1;
|
||
RM.PassagewayBrightness2 = this.PassagewayBrightness2;
|
||
RM.PassagewayBrightness3 = this.PassagewayBrightness3;
|
||
RM.PassagewayBrightness4 = this.PassagewayBrightness4;
|
||
}
|
||
|
||
|
||
RM.MyROI.ModelFeaturePiont.hv_RefRow = rm.MyROI.ModelFeaturePiont.hv_RefRow;
|
||
RM.MyROI.ModelFeaturePiont.hv_RefColumn = rm.MyROI.ModelFeaturePiont.hv_RefColumn;
|
||
|
||
//矩形参数
|
||
RM.MyROI.hv_Row = rm.MyROI.hv_Row;
|
||
RM.MyROI.hv_Row1 = rm.MyROI.hv_Row1;
|
||
RM.MyROI.hv_Column = rm.MyROI.hv_Column;
|
||
RM.MyROI.hv_Column1 = rm.MyROI.hv_Column1;
|
||
|
||
//圆形参数
|
||
RM.MyROI.RoiShape = rm.MyROI.RoiShape;
|
||
RM.MyROI.hv_Radius = rm.MyROI.hv_Radius;
|
||
|
||
//可变矩形参数
|
||
RM.MyROI.hv_Phi = rm.MyROI.hv_Phi;
|
||
RM.MyROI.hv_length1 = rm.MyROI.hv_length1;
|
||
RM.MyROI.hv_length2 = rm.MyROI.hv_length2;
|
||
|
||
|
||
RM.Instantiation();
|
||
RM.MyROI.Initialize();
|
||
RM.MyROI.hv_ModelID = rm.MyROI.hv_ModelID;
|
||
RM.MyROI.ho_OutlineROI = rm.MyROI.ho_OutlineROI;
|
||
|
||
//if (SaveAll(RM) && RM.MyROI.SaveFeatureModel()&& RM.MyROI.Save_roi_Region())
|
||
if (SaveAll(RM) && RM.MyROI.SaveFeatureModel())
|
||
{
|
||
string filePath = @"Image/" + RM.MyROI.HelpFileName + ".bmp"; //模板图片路径
|
||
HOperatorSet.WriteImage(Ho_Image, "bmp", 0, filePath); //保存模板图片
|
||
}
|
||
else
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
CreateModeling = false;
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 创建模型参数
|
||
/// <summary>
|
||
/// 创建模型参数
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public HObject ModelPerReduction(V_RectangleModel RM)
|
||
{
|
||
HTuple hv_ModelID = null, hv_ModelRegionArea = null;
|
||
HTuple hv_RefRow = null, hv_RefColumn = null, hv_HomMat2D = null;
|
||
HTuple hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Angle = new HTuple();
|
||
HTuple hv_Score = new HTuple(), hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple();
|
||
|
||
|
||
HObject ho_ModelRegion;
|
||
HObject ho_ModelContours, ho_TransContours;
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ModelRegion);
|
||
HOperatorSet.GenEmptyObj(out ho_ModelContours);
|
||
HOperatorSet.GenEmptyObj(out ho_TransContours);
|
||
|
||
try
|
||
{
|
||
//2,绘制区域模型
|
||
RM.Instantiation();
|
||
//截取矩形选框中的图像
|
||
HObject ho_ImageRM;
|
||
HOperatorSet.GenEmptyObj(out ho_ImageRM);
|
||
HOperatorSet.ReduceDomain(Ho_Image, RM.ho_RectangleModel, out ho_ImageRM);
|
||
|
||
//3,绘制ROI
|
||
// RM.MyROI.Initialize();
|
||
//截取矩形选框中的图像
|
||
HObject ho_ImageROI;
|
||
HOperatorSet.GenEmptyObj(out ho_ImageROI);
|
||
HOperatorSet.ReduceDomain(ho_ImageRM, RM.MyROI.ho_OutlineROI, out ho_ImageROI);
|
||
|
||
HOperatorSet.CreateShapeModel(ho_ImageROI, "auto", (new HTuple(0)).TupleRad(), (new HTuple(360)).TupleRad(), "auto", "auto", "use_polarity", "auto", "auto", out hv_ModelID);
|
||
// HOperatorSet.CreateShapeModel(ho_ImageROI, "auto", (new HTuple(0)).TupleRad(), (new HTuple(360)).TupleRad(), "auto", (new HTuple("point_reduction_medium")).TupleConcat("no_pregeneration"), "use_polarity", "auto", "auto", out hv_ModelID);
|
||
//模型将它转换成图像的轮廓
|
||
ho_ModelContours.Dispose();
|
||
HOperatorSet.GetShapeModelContours(out ho_ModelContours, hv_ModelID, 1);
|
||
//
|
||
//获取参考位置
|
||
HOperatorSet.AreaCenter(RM.MyROI.ho_OutlineROI, out hv_ModelRegionArea, out hv_RefRow, out hv_RefColumn);
|
||
HOperatorSet.VectorAngleToRigid(0, 0, 0, hv_RefRow, hv_RefColumn, 0, out hv_HomMat2D);
|
||
ho_TransContours.Dispose();
|
||
HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_TransContours, hv_HomMat2D);
|
||
|
||
RM.MyROI.hv_ModelID = hv_ModelID;
|
||
RM.MyROI.ModelFeaturePiont.hv_RefRow = hv_RefRow;
|
||
RM.MyROI.ModelFeaturePiont.hv_RefColumn = hv_RefColumn;
|
||
|
||
return ho_TransContours;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 特征匹配
|
||
/// <summary>
|
||
/// 特征匹配
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public bool FeatureMatchingIng(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
|
||
var RM = VEI.MyRectangleModel;
|
||
bool pipeiOK = false;
|
||
|
||
if (RM == null || RM.ID <= 0)
|
||
{
|
||
MessageBox.Show("请选择测试项目");
|
||
return pipeiOK;
|
||
}
|
||
|
||
HObject ho_ImageReduced, ho_ModelContours, ho_TransContours, ho_ImageROI;
|
||
HTuple hv_HomMat2D = null;
|
||
HTuple hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Angle = new HTuple();
|
||
HTuple hv_Score = new HTuple(), hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple();
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_ModelContours);
|
||
HOperatorSet.GenEmptyObj(out ho_TransContours);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageROI);
|
||
|
||
// SetLight(RM);
|
||
//1,获取图像
|
||
if (!GetImage(RM))
|
||
{
|
||
return pipeiOK;
|
||
}
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
//RM.MyROI.ShapeA_Min = 10;
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
HObject ho_ImageScaled;
|
||
HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
Ho_Image = ho_ImageScaled;
|
||
}
|
||
ShowObj(Ho_Image);
|
||
//去畸变
|
||
// DeDistortion();
|
||
try
|
||
{
|
||
//读取模型文件
|
||
if (!RM.MyROI.ReadFeatureModel())
|
||
{
|
||
ShowTextPer("读取特征模型文件失败", "red");
|
||
return pipeiOK;
|
||
}
|
||
|
||
RM.Instantiation();
|
||
//截取矩形选框中的图像
|
||
HOperatorSet.ReduceDomain(Ho_Image, RM.ho_RectangleModel, out ho_ImageReduced);
|
||
//识别图像特征
|
||
HOperatorSet.FindShapeModel(ho_ImageReduced, RM.MyROI.hv_ModelID, (new HTuple(0)).TupleRad(), (new HTuple(360)).TupleRad(), RM.MyROI.RecognitionCoefficient, 1, 1, (new HTuple("least_squares")).TupleConcat("max_deformation 5"), 0, 0.8, out hv_Row, out hv_Column, out hv_Angle, out hv_Score);
|
||
//HOperatorSet.FindShapeModel(ho_ImageReduced, RM.MyROI.hv_ModelID, (new HTuple(0)).TupleRad(), (new HTuple(360)).TupleRad(), RM.MyROI.RecognitionCoefficient, 10, 1, "least_squares", 0, 0.8, out hv_Row, out hv_Column, out hv_Angle, out hv_Score);
|
||
|
||
if (hv_Score == null || hv_Score.TupleLength() <= 0)
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
return pipeiOK;
|
||
}
|
||
else
|
||
{
|
||
|
||
//模型将它转换成图像的轮廓
|
||
|
||
HOperatorSet.GetShapeModelContours(out ho_ModelContours, RM.MyROI.hv_ModelID, 1);
|
||
for (int i = 0; i <= hv_Score.TupleLength() - 1; i++)
|
||
{
|
||
HOperatorSet.HomMat2dIdentity(out hv_HomMat2D);
|
||
HOperatorSet.HomMat2dRotate(hv_HomMat2D, hv_Angle.TupleSelect(i), 0, 0, out hv_HomMat2D);
|
||
HOperatorSet.HomMat2dTranslate(hv_HomMat2D, hv_Row.TupleSelect(i), hv_Column.TupleSelect(i), out hv_HomMat2D);
|
||
|
||
HOperatorSet.AffineTransContourXld(ho_ModelContours, out ho_TransContours, hv_HomMat2D);
|
||
|
||
SetDraw("margin");
|
||
//显示矩形区域
|
||
ShowObj(RM.ho_RectangleModel, "blue");
|
||
|
||
//显示特征
|
||
ShowObj(ho_TransContours, "green");
|
||
|
||
}
|
||
|
||
if (hv_Score.TupleLength() > 1)
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
return pipeiOK;
|
||
}
|
||
|
||
|
||
RM.MyROI.ModelFeaturePiont.PixelRow = hv_Row.TupleSelect(0);
|
||
RM.MyROI.ModelFeaturePiont.PixelColumn = hv_Column.TupleSelect(0);
|
||
|
||
//弧度转角度
|
||
RM.MyROI.ModelFeaturePiont.AngleU = hv_Angle.TupleSelect(0).TupleDeg().D;
|
||
|
||
|
||
|
||
#region 标准标定文件读取
|
||
//读取外部标定文件
|
||
//string ParametersPath = @"Calibration/" + MachineObj.MachineName + SelectModel.ID + MachineObj.SoftID + "_CameraParameters.dat"; //相机内参保存路径
|
||
//string PosePath= @"Calibration/" + MachineObj.MachineName + SelectModel.ID + MachineObj.SoftID + "_CameraPose.dat"; //姿态参数
|
||
|
||
// HTuple hv_X_World = null, hv_Y_World = null;
|
||
//if (File.Exists(ParametersPath)&&File.Exists(PosePath))
|
||
//{
|
||
// if (WhetherReadFile)
|
||
// {
|
||
// HOperatorSet.ReadCamPar(ParametersPath, out hv_ReadCameraParameters); //读取相机内参
|
||
// HOperatorSet.ReadPose(PosePath, out hv_ReadPose); //读取相机外参
|
||
//WhetherReadFile = false;
|
||
// }
|
||
|
||
// //像素坐标转换成世界坐标
|
||
// HOperatorSet.ImagePointsToWorldPlane(hv_ReadCameraParameters, hv_ReadPose, RM.CharacteristicsROI.ModelFeaturePiont.DeviationX, RM.CharacteristicsROI.ModelFeaturePiont.DeviationY, 0.001, out hv_X_World, out hv_Y_World);
|
||
|
||
// RM.CharacteristicsROI.ModelFeaturePiont.DeviationX = hv_X_World;
|
||
// RM.CharacteristicsROI.ModelFeaturePiont.DeviationY = hv_Y_World;
|
||
|
||
// HOperatorSet.WriteString(HWindowWPF.HalconWindow, "世界坐标" + "X:" + RM.CharacteristicsROI.ModelFeaturePiont.DeviationX + ",Y:" + RM.CharacteristicsROI.ModelFeaturePiont.DeviationY + ",U:" + RM.CharacteristicsROI.ModelFeaturePiont.AngleU);
|
||
//}
|
||
//else
|
||
//{
|
||
// HOperatorSet.WriteString(HWindowWPF.HalconWindow,"像素坐标"+ "X:" + RM.CharacteristicsROI.ModelFeaturePiont.DeviationX + ",Y:" + RM.CharacteristicsROI.ModelFeaturePiont.DeviationY + ",U:" + RM.CharacteristicsROI.ModelFeaturePiont.AngleU);
|
||
//}
|
||
#endregion
|
||
|
||
//读取已标定文件
|
||
if (RM.ReadCalibrationPar(Camera.CamName))
|
||
{
|
||
HTuple WordRow = null, WordColumn = null, hv_RefRow = null, hv_RefColumn = null;
|
||
//像素坐标转换成世界坐标
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, (HTuple)RM.MyROI.ModelFeaturePiont.PixelRow, (HTuple)RM.MyROI.ModelFeaturePiont.PixelColumn, out WordRow, out WordColumn);
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, (HTuple)RM.MyROI.ModelFeaturePiont.hv_RefRow, (HTuple)RM.MyROI.ModelFeaturePiont.hv_RefColumn, out hv_RefRow, out hv_RefColumn);
|
||
|
||
|
||
CurrPoint = new MyPoint() { X = Math.Round(WordColumn.D, 4), Y = Math.Round(WordRow.D, 4), Angle = hv_Angle.TupleDeg().D };
|
||
|
||
CurrOffs = new MyPoint();
|
||
CurrOffs.X = Math.Round(WordColumn.D - hv_RefColumn.D, 4);
|
||
CurrOffs.Y = Math.Round(WordRow.D - hv_RefRow.D, 4);
|
||
CurrOffs.Angle = CurrPoint.Angle;
|
||
|
||
|
||
CurrLocationPoint = new MyPoint();
|
||
CurrLocationPoint.X = Math.Round(hv_RefColumn.D, 4);
|
||
CurrLocationPoint.Y = Math.Round(hv_RefRow.D, 4);
|
||
CurrLocationPoint.Angle = RM.MyROI.ModelFeaturePiont.AngleU;
|
||
|
||
ShowText("绝对" + " X:" + CurrPoint.X + ", Y:" + CurrPoint.Y + ", U:" + CurrPoint.Angle, "green");
|
||
ShowText("基准" + " X:" + CurrLocationPoint.X + ", Y:" + CurrLocationPoint.Y + ", U:" + CurrLocationPoint.Angle, "green", 20, 2);
|
||
ShowText("偏移" + " X:" + CurrOffs.X + ", Y:" + CurrOffs.Y + ", U:" + CurrOffs.Angle, "green", 20, 4);
|
||
|
||
}
|
||
else
|
||
{
|
||
double x = RM.MyROI.ModelFeaturePiont.PixelRow - RM.MyROI.ModelFeaturePiont.hv_RefRow;
|
||
double y = RM.MyROI.ModelFeaturePiont.PixelColumn - RM.MyROI.ModelFeaturePiont.hv_RefColumn;
|
||
|
||
ShowText("像素坐标" + "X:" + Math.Round(x, 4) + ",Y:" + Math.Round(y, 4) + ",U:" + Math.Round(RM.MyROI.ModelFeaturePiont.AngleU, 4), "green");
|
||
}
|
||
|
||
pipeiOK = true;
|
||
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
|
||
|
||
return pipeiOK;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 世界坐标
|
||
/// </summary>
|
||
public MyPoint CurrPoint { get; set; }
|
||
/// <summary>
|
||
/// 像素坐标
|
||
/// </summary>
|
||
public MyPoint CurrPixPoint { get; set; }
|
||
|
||
/// <summary>
|
||
/// 基准
|
||
/// </summary>
|
||
public MyPoint CurrLocationPoint { get; set; }
|
||
/// <summary>
|
||
/// 偏移
|
||
/// </summary>
|
||
public MyPoint CurrOffs { get; set; }
|
||
/// <summary>
|
||
/// 特征匹配-抓取角点
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public bool FeatureMatchingJiaodian(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
var lastExposureTime = Camera.ExposureTime;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
var RM = VEI.MyRectangleModel;
|
||
bool pipeiOK = false;
|
||
|
||
if (RM == null || RM.ID <= 0)
|
||
{
|
||
ShowText("请选择测试项目", "red");
|
||
return pipeiOK;
|
||
}
|
||
|
||
HObject ho_ImageReduced, ho_ModelContours, ho_TransContours, ho_ImageROI;
|
||
HTuple hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Angle = new HTuple();
|
||
HTuple hv_Score = new HTuple(), hv_I = new HTuple(), hv_RectificationHomMat2D = new HTuple();
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_ModelContours);
|
||
HOperatorSet.GenEmptyObj(out ho_TransContours);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageROI);
|
||
|
||
HTuple hv_Rowex = null, hv_Columnex = null, hv_Angle1 = null;
|
||
double RX = 0, RY = 0;
|
||
|
||
// SetLight(RM);
|
||
//1,获取图像
|
||
if (!GetImage(RM))
|
||
{
|
||
return pipeiOK;
|
||
}
|
||
|
||
//CloseSetLight(RM);
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
HObject ho_ImageScaled;
|
||
// HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, 1.90299, -230);
|
||
HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
Ho_Image = ho_ImageScaled;
|
||
}
|
||
|
||
|
||
ShowObj(Ho_Image);
|
||
//去畸变
|
||
// DeDistortion();
|
||
try
|
||
{
|
||
|
||
FindPoint(Ho_Image, RM.MyCorner, out hv_Rowex, out hv_Columnex, out hv_Angle, out hv_Angle1);
|
||
|
||
|
||
CurrPixPoint = new MyPoint() { X = hv_Rowex.D, Y = hv_Columnex.D };
|
||
RM.MyROI.ModelFeaturePiont.AngleU = hv_Angle.TupleDeg().D;
|
||
//读取已标定文件
|
||
if (RM.ReadCalibrationPar(Camera.CamName))
|
||
{
|
||
HTuple WordRow = 0, WordColumn = 0, hv_RefRow = null, hv_RefColumn = null; ;
|
||
//像素坐标转换成世界坐标
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, hv_Rowex, hv_Columnex, out WordRow, out WordColumn);
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, (HTuple)RM.MyROI.ModelFeaturePiont.hv_RefRow, (HTuple)RM.MyROI.ModelFeaturePiont.hv_RefColumn, out hv_RefRow, out hv_RefColumn);
|
||
CurrPoint = new MyPoint() { X = Math.Round(WordColumn.D, 4), Y = Math.Round(WordRow.D, 4), Angle = hv_Angle.TupleDeg().D };
|
||
|
||
CurrOffs = new MyPoint();
|
||
CurrOffs.X = Math.Round(WordColumn.D - hv_RefColumn.D, 4);
|
||
CurrOffs.Y = Math.Round(WordRow.D - hv_RefRow.D, 4);
|
||
CurrOffs.Angle = CurrPoint.Angle - RM.MyROI.ModelFeaturePiont.AngleU;
|
||
|
||
|
||
CurrLocationPoint = new MyPoint();
|
||
CurrLocationPoint.X = Math.Round(hv_RefColumn.D, 4);
|
||
CurrLocationPoint.Y = Math.Round(hv_RefRow.D, 4);
|
||
CurrLocationPoint.Angle = RM.MyROI.ModelFeaturePiont.AngleU;
|
||
|
||
ShowText("绝对" + " X:" + CurrPoint.X + ", Y:" + CurrPoint.Y + ", U:" + CurrPoint.Angle, "green");
|
||
ShowText("基准" + " X:" + CurrLocationPoint.X + ", Y:" + CurrLocationPoint.Y + ", U:" + CurrLocationPoint.Angle, "green", 20, 2);
|
||
ShowText("偏移" + " X:" + CurrOffs.X + ", Y:" + CurrOffs.Y + ", U:" + CurrOffs.Angle, "green", 20, 4);
|
||
|
||
|
||
pipeiOK = true;
|
||
}
|
||
else
|
||
{
|
||
ShowText("像素坐标" + "X:" + CurrPixPoint.X + ",Y:" + CurrPixPoint.Y, "green");
|
||
}
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
|
||
return pipeiOK;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 抓矩形
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public bool FeatureMatchingRectangle2(V_RectangleModel RM, bool qutu = true)
|
||
{
|
||
bool pipeiOK = false;
|
||
if (RM == null || RM.ID <= 0)
|
||
{
|
||
ShowText("请选择测试项目", "red", 20);
|
||
return pipeiOK;
|
||
}
|
||
|
||
HObject ho_ImageReduced, ho_ImageScaled;
|
||
|
||
HTuple hv_Row = null, hv_Column = null, hv_Phi = null;
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageScaled);
|
||
try
|
||
{
|
||
|
||
// SetLight(RM);
|
||
//1,获取图像
|
||
if (qutu && !GetImage(RM))
|
||
{
|
||
return pipeiOK;
|
||
}
|
||
|
||
//CloseSetLight(RM);
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
// HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, 1.90299, -230);
|
||
HOperatorSet.ScaleImage(Ho_Image, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
|
||
}
|
||
else
|
||
{
|
||
ho_ImageScaled = Ho_Image.Clone();
|
||
}
|
||
|
||
|
||
// ShowObj(ho_ImageScaled);
|
||
|
||
double RX = 0, RY = 0;
|
||
|
||
RM.Instantiation();
|
||
//截取矩形选框中的图像
|
||
HOperatorSet.ReduceDomain(ho_ImageScaled, RM.ho_RectangleModel, out ho_ImageReduced);
|
||
bool res = FindRectangle2_A(ho_ImageReduced, RM, out hv_Row, out hv_Column, out hv_Phi);
|
||
|
||
if (res)
|
||
{
|
||
double angelee = hv_Phi.TupleDeg().D;
|
||
if (angelee > 45)
|
||
{
|
||
angelee = -(90 - angelee);
|
||
}
|
||
else if (angelee < -45)
|
||
{
|
||
angelee = 90 + angelee;
|
||
}
|
||
|
||
CurrPixPoint = new MyPoint() { X = Math.Round(hv_Row.D, 4), Y = Math.Round(hv_Column.D, 4), Angle = Math.Round(angelee, 4) };
|
||
//读取已标定文件
|
||
if (RM.ReadCalibrationPar(Camera.CamName))
|
||
{
|
||
//HTuple WordRow = 0, WordColumn = 0;
|
||
////像素坐标转换成世界坐标
|
||
//HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, hv_Row2, hv_Column2, out WordRow, out WordColumn);
|
||
//CurrPoint = new MyPoint() { X = Math.Round(RX + WordRow.D, 4), Y = Math.Round(RY + WordColumn.D, 4) };
|
||
|
||
|
||
HTuple WordRow = null, WordColumn = null, hv_RefRow = null, hv_RefColumn = null;
|
||
//像素坐标转换成世界坐标
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, hv_Row, hv_Column, out WordRow, out WordColumn);
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, (HTuple)RM.MyROI.ModelFeaturePiont.hv_RefRow, (HTuple)RM.MyROI.ModelFeaturePiont.hv_RefColumn, out hv_RefRow, out hv_RefColumn);
|
||
|
||
CurrPoint = new MyPoint();
|
||
CurrPoint.X = Math.Round(WordRow.D - hv_RefRow.D, 4);
|
||
CurrPoint.Y = Math.Round(WordColumn.D - hv_RefColumn.D, 4);
|
||
CurrPoint.Angle = Math.Round(angelee - RM.MyROI.ModelFeaturePiont.AngleU, 4);
|
||
|
||
|
||
|
||
ShowText("世界坐标" + " X:" + CurrPoint.X + ", Y:" + CurrPoint.Y + ", U:" + CurrPoint.Angle, "green", 20);
|
||
//ShowText("像素坐标" + " X:" + CurrPixPoint.X + ", Y:" + CurrPixPoint.Y + ", U:" + Math.Round(angelee, 4), "green", 20, 2);
|
||
}
|
||
else
|
||
{
|
||
ShowText("像素坐标" + " X:" + CurrPixPoint.X + ", Y:" + CurrPixPoint.Y + ", U:" + Math.Round(angelee, 4), "green", 20);
|
||
}
|
||
|
||
pipeiOK = true;
|
||
}
|
||
else
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
pipeiOK = false;
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
|
||
ho_ImageReduced.Dispose();
|
||
ho_ImageScaled.Dispose();
|
||
|
||
return pipeiOK;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 找到圆的个数
|
||
/// </summary>
|
||
public int CircleCount { get; set; }
|
||
/// <summary>
|
||
/// 抓圆
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public bool FeatureMatchingCirCle(V_RectangleModel RM, bool qutu = true)
|
||
{
|
||
bool pipeiOK = false;
|
||
if (RM == null || RM.ID <= 0)
|
||
{
|
||
ShowText("请选择测试项目", "red", 20);
|
||
return pipeiOK;
|
||
}
|
||
|
||
HObject ho_ImageReduced, ho_ImageScaled;
|
||
|
||
HTuple hv_Row = new HTuple(), hv_Column = new HTuple(), hv_Parameter;
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageScaled);
|
||
|
||
try
|
||
{
|
||
//1,获取图像
|
||
if (qutu && !GetImage(RM))
|
||
{
|
||
return pipeiOK;
|
||
}
|
||
|
||
|
||
|
||
|
||
ho_ImageScaled = Ho_Image.Clone();
|
||
ShowObj(Ho_Image);
|
||
|
||
RM.Instantiation();
|
||
//截取矩形选框中的图像
|
||
HOperatorSet.ReduceDomain(ho_ImageScaled, RM.ho_RectangleModel, out ho_ImageReduced);
|
||
List<V_Piont> list = new List<V_Piont>();
|
||
bool res = FindCircle(ho_ImageScaled, RM, out list);
|
||
|
||
if (res)
|
||
{
|
||
//List<V_Piont> list = new List<V_Piont>();
|
||
//int a = 0;
|
||
//V_Piont p = new V_Piont();
|
||
//foreach (var item in hv_Parameter.ToDArr())
|
||
//{
|
||
// if (a == 0)
|
||
// {
|
||
// p = new V_Piont() { hv_RefRow = item };
|
||
// a++;
|
||
// }
|
||
// else if (a == 1)
|
||
// {
|
||
// p.hv_RefColumn = item;
|
||
// a++;
|
||
// }
|
||
// else if (a == 2)
|
||
// {
|
||
// a = 0;
|
||
// list.Add(p);
|
||
// }
|
||
|
||
//}
|
||
|
||
|
||
CircleCount = list.Count;
|
||
int a = 0;
|
||
//读取已标定文件
|
||
if (RM.ReadCalibrationPar(Camera.CamName))
|
||
{
|
||
HTuple WordRow = null, WordColumn = null, hv_RefRow, hv_RefColumn;
|
||
|
||
a = 0;
|
||
|
||
foreach (var item in list)
|
||
{
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, item.hv_RefRow, item.hv_RefColumn, 60, 0);
|
||
ShowObj(ho_Cross, "green");
|
||
|
||
//像素坐标转换成世界坐标
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, item.hv_RefRow, item.hv_RefColumn, out WordRow, out WordColumn);
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, RM.LocateList[a].hv_RefRow, RM.LocateList[a].hv_RefColumn, out hv_RefRow, out hv_RefColumn);
|
||
CurrLocationPoint = new MyPoint();
|
||
CurrLocationPoint.Y = Math.Round(WordRow.D - hv_RefRow.D, 4);
|
||
CurrLocationPoint.X = Math.Round(WordColumn.D - hv_RefColumn.D, 4);
|
||
RM.LocateList[a].DeviationY = CurrLocationPoint.Y;
|
||
RM.LocateList[a].DeviationX = CurrLocationPoint.X;
|
||
a++;
|
||
ShowText(a + " X:" + CurrLocationPoint.X + ", Y:" + CurrLocationPoint.Y, item.hv_RefRow + 20, item.hv_RefColumn + 20, "green", 20);
|
||
|
||
}
|
||
|
||
pipeiOK = true;
|
||
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
//ShowText("像素坐标" + " X:" + CurrPixPoint.X + ", Y:" + CurrPixPoint.Y, "green", 20);
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
pipeiOK = false;
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
|
||
ho_ImageReduced.Dispose();
|
||
ho_ImageScaled.Dispose();
|
||
|
||
return pipeiOK;
|
||
}
|
||
|
||
public MyPoint BigCirClePix { get; set; }
|
||
public MyPoint SmallCirClePix { get; set; }
|
||
|
||
public MyPoint BigCirCle { get; set; }
|
||
public MyPoint SmallCirCle { get; set; }
|
||
private bool FindTwoCirCle(V_RectangleModel RM)
|
||
{
|
||
BigCirClePix = new MyPoint();
|
||
SmallCirClePix = new MyPoint();
|
||
// Local iconic variables
|
||
|
||
HObject ho_GrayImage;
|
||
HObject ho_Rectangle, ho_Regions1, ho_ConnectedRegions2;
|
||
HObject ho_FillRegions1, ho_ConnectedRegions1, ho_SelectedRegions;
|
||
HObject ho_Contours1, ho_ContCircle1, ho_Cross1, ho_RegionOpening;
|
||
HObject ho_ImageReduced, ho_Regions, ho_ConnectedRegions;
|
||
HObject ho_SelectedRegions1, ho_RegionTrans1, ho_RegionDifference;
|
||
HObject ho_RegionOpening1, ho_ConnectedRegions3, ho_SelectedRegions2;
|
||
HObject ho_Contours, ho_ContoursSplit1, ho_SelectedXLD;
|
||
HObject ho_UnionContours, ho_ContCircle, ho_Cross;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_WindowHandle = new HTuple(), hv_Row1 = new HTuple();
|
||
HTuple hv_Column1 = new HTuple(), hv_Row21 = new HTuple();
|
||
HTuple hv_Column21 = new HTuple(), hv_Row4 = new HTuple();
|
||
HTuple hv_Column4 = new HTuple(), hv_Radius1 = new HTuple();
|
||
HTuple hv_StartPhi1 = new HTuple(), hv_EndPhi1 = new HTuple();
|
||
HTuple hv_PointOrder2 = new HTuple(), hv_Area1 = new HTuple();
|
||
HTuple hv_Row3 = new HTuple(), hv_Column3 = new HTuple();
|
||
HTuple hv_PointOrder3 = new HTuple(), hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Radius = new HTuple();
|
||
HTuple hv_StartPhi = new HTuple(), hv_EndPhi = new HTuple();
|
||
HTuple hv_PointOrder = new HTuple(), hv_Area = new HTuple();
|
||
HTuple hv_Row2 = new HTuple(), hv_Column2 = new HTuple();
|
||
HTuple hv_PointOrder1 = new HTuple();
|
||
// Initialize local and output iconic variables
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_GrayImage);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle);
|
||
HOperatorSet.GenEmptyObj(out ho_Regions1);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions2);
|
||
HOperatorSet.GenEmptyObj(out ho_FillRegions1);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours1);
|
||
HOperatorSet.GenEmptyObj(out ho_ContCircle1);
|
||
HOperatorSet.GenEmptyObj(out ho_Cross1);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionOpening);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_Regions);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionTrans1);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionDifference);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions3);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours);
|
||
HOperatorSet.GenEmptyObj(out ho_ContoursSplit1);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedXLD);
|
||
HOperatorSet.GenEmptyObj(out ho_UnionContours);
|
||
HOperatorSet.GenEmptyObj(out ho_ContCircle);
|
||
HOperatorSet.GenEmptyObj(out ho_Cross);
|
||
|
||
try
|
||
{
|
||
|
||
|
||
|
||
ho_ImageReduced.Dispose();
|
||
RM.Instantiation();
|
||
//截取矩形选框中的图像
|
||
HOperatorSet.ReduceDomain(ho_Image, RM.ho_RectangleModel, out ho_ImageReduced);
|
||
|
||
ho_GrayImage.Dispose();
|
||
HOperatorSet.Rgb1ToGray(ho_ImageReduced, out ho_GrayImage);
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
// HOperatorSet.Rgb1ToGray(Ho_Image, out HObject ho_GrayImage);
|
||
HOperatorSet.ScaleImage(ho_GrayImage, out ho_GrayImage, hv_Mult, hv_Add);
|
||
//if (RM.MyROI.ShapeC_Max > 0)
|
||
//{
|
||
// ShowObj(ho_GrayImage);
|
||
//}
|
||
}
|
||
//
|
||
|
||
//二值化
|
||
ho_Regions1.Dispose();
|
||
HOperatorSet.Threshold(ho_GrayImage, out ho_Regions, RM.MyROI.ThresholdMin, RM.MyROI.ThresholdMax);
|
||
SetDraw("fill");
|
||
if (RM.MyROI.ShapeB_Min > 0)
|
||
{
|
||
ShowObj(ho_Regions);
|
||
}
|
||
|
||
ho_ConnectedRegions2.Dispose();
|
||
HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions2);
|
||
|
||
|
||
ho_FillRegions1.Dispose();
|
||
HOperatorSet.FillUp(ho_ConnectedRegions2, out ho_FillRegions1);
|
||
// ShowObj(ho_FillRegions1);
|
||
ho_ConnectedRegions1.Dispose();
|
||
HOperatorSet.Connection(ho_FillRegions1, out ho_ConnectedRegions1);
|
||
|
||
//拿到最大的园
|
||
ho_SelectedRegions.Dispose();
|
||
HOperatorSet.SelectShapeStd(ho_ConnectedRegions1, out ho_SelectedRegions, "max_area", 170);
|
||
|
||
|
||
|
||
HOperatorSet.OpeningCircle(ho_SelectedRegions, out ho_RegionOpening, 30);
|
||
//if (RM.MyROI.ShapeC_Min > 0)
|
||
//{
|
||
// ShowObj(ho_RegionOpening);
|
||
//}
|
||
|
||
ho_Contours1.Dispose();
|
||
HOperatorSet.GenContourRegionXld(ho_RegionOpening, out ho_Contours1, "border");
|
||
|
||
HOperatorSet.FitCircleContourXld(ho_Contours1, "atukey", -1, 0, 0, 3, 2, out hv_Row4,
|
||
out hv_Column4, out hv_Radius1, out hv_StartPhi1, out hv_EndPhi1, out hv_PointOrder2);
|
||
ho_ContCircle1.Dispose();
|
||
HOperatorSet.GenCircleContourXld(out ho_ContCircle1, hv_Row4, hv_Column4, hv_Radius1,
|
||
0, 6.28318, "positive", 1);
|
||
//获得大圆的中心坐标
|
||
|
||
HOperatorSet.AreaCenterXld(ho_ContCircle1, out hv_Area1, out hv_Row3, out hv_Column3, out hv_PointOrder3);
|
||
|
||
SetDraw("margin");
|
||
ShowObj(ho_ContCircle1);
|
||
ho_Cross1.Dispose();
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross1, hv_Row3, hv_Column3, 60, 0);
|
||
BigCirClePix.X = hv_Column3.D;
|
||
BigCirClePix.Y = hv_Row3.D;
|
||
ShowObj(ho_Cross1);
|
||
//return true;
|
||
//找小圆
|
||
ho_RegionOpening.Dispose();
|
||
//HOperatorSet.OpeningCircle(ho_SelectedRegions, out ho_RegionOpening, 100);
|
||
HOperatorSet.OpeningCircle(ho_SelectedRegions, out ho_RegionOpening, 100);
|
||
SetDraw("fill");
|
||
|
||
|
||
ho_ImageReduced.Dispose();
|
||
HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
|
||
|
||
HOperatorSet.ReduceDomain(ho_GrayImage, ho_RegionOpening, out ho_ImageReduced);
|
||
|
||
ho_Regions.Dispose();
|
||
//HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, 150, 255);
|
||
|
||
// HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, 100, 255);
|
||
HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, RM.MyROI.ShapeC_Min, RM.MyROI.ShapeC_Max);
|
||
// ShowObj(ho_Regions);
|
||
|
||
ho_ConnectedRegions.Dispose();
|
||
HOperatorSet.ClosingCircle(ho_Regions, out ho_Regions, 10);
|
||
|
||
|
||
HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
|
||
ho_SelectedRegions1.Dispose();
|
||
HOperatorSet.SelectShapeStd(ho_ConnectedRegions, out ho_SelectedRegions1, "max_area", 170);
|
||
|
||
//ShowObj(ho_SelectedRegions1);
|
||
ho_RegionTrans1.Dispose();
|
||
HOperatorSet.ShapeTrans(ho_SelectedRegions1, out ho_RegionTrans1, "outer_circle");
|
||
//ShowObj(ho_RegionTrans1);
|
||
//ho_RegionDifference.Dispose();
|
||
|
||
if (RM.MyROI.ShapeB_Max > 0)
|
||
{
|
||
|
||
ho_RegionDifference = ho_SelectedRegions1;
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.Difference(ho_RegionTrans1, ho_SelectedRegions1, out ho_RegionDifference);
|
||
|
||
// ShowObj(ho_RegionDifference);
|
||
}
|
||
|
||
ho_RegionOpening1.Dispose();
|
||
if (RM.MyROI.ShapeB_Max > 0)
|
||
{
|
||
HOperatorSet.OpeningCircle(ho_RegionDifference, out ho_RegionOpening1, 50);
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.OpeningCircle(ho_RegionDifference, out ho_RegionOpening1, 10);
|
||
}
|
||
|
||
//ShowObj(ho_RegionOpening1);
|
||
ho_ConnectedRegions3.Dispose();
|
||
HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions3);
|
||
ho_SelectedRegions2.Dispose();
|
||
HOperatorSet.SelectShapeStd(ho_ConnectedRegions3, out ho_SelectedRegions2, "max_area", 70);
|
||
ho_Contours.Dispose();
|
||
HOperatorSet.GenContourRegionXld(ho_SelectedRegions2, out ho_Contours, "border");
|
||
ho_ContoursSplit1.Dispose();
|
||
HOperatorSet.SegmentContoursXld(ho_Contours, out ho_ContoursSplit1, "lines_circles", 9, 50, 50);
|
||
ho_SelectedXLD.Dispose();
|
||
HOperatorSet.SelectShapeXld(ho_ContoursSplit1, out ho_SelectedXLD, "circularity", "and", 0.05, 1);
|
||
ho_UnionContours.Dispose();
|
||
HOperatorSet.UnionAdjacentContoursXld(ho_SelectedXLD, out ho_UnionContours, 10, 1, "attr_keep");
|
||
//union_cocircular_contours_xld (SelectedXLD, UnionContours, 0.5, 0.1, 0.2, 30, 10, 10, 'true', 1)
|
||
|
||
HOperatorSet.FitCircleContourXld(ho_UnionContours, "algebraic", -1, 0, 0, 3,
|
||
2, out hv_Row, out hv_Column, out hv_Radius, out hv_StartPhi, out hv_EndPhi,
|
||
out hv_PointOrder);
|
||
ho_ContCircle.Dispose();
|
||
HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column, hv_Radius,
|
||
0, 6.28318, "positive", 1);
|
||
|
||
SetDraw("margin");
|
||
ShowObj(ho_ContCircle);
|
||
HOperatorSet.AreaCenterXld(ho_ContCircle, out hv_Area, out hv_Row2, out hv_Column2, out hv_PointOrder1);
|
||
ho_Cross.Dispose();
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row2, hv_Column2, 60, 0);
|
||
SmallCirClePix.X = hv_Column2.D;
|
||
SmallCirClePix.Y = hv_Row2.D;
|
||
ShowObj(ho_Cross);
|
||
return true;
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
return false;
|
||
}
|
||
finally
|
||
{
|
||
|
||
ho_GrayImage.Dispose();
|
||
ho_Rectangle.Dispose();
|
||
ho_Regions1.Dispose();
|
||
ho_ConnectedRegions2.Dispose();
|
||
ho_FillRegions1.Dispose();
|
||
ho_ConnectedRegions1.Dispose();
|
||
ho_SelectedRegions.Dispose();
|
||
ho_Contours1.Dispose();
|
||
ho_ContCircle1.Dispose();
|
||
ho_Cross1.Dispose();
|
||
ho_RegionOpening.Dispose();
|
||
ho_ImageReduced.Dispose();
|
||
ho_Regions.Dispose();
|
||
ho_ConnectedRegions.Dispose();
|
||
ho_SelectedRegions1.Dispose();
|
||
ho_RegionTrans1.Dispose();
|
||
ho_RegionDifference.Dispose();
|
||
ho_RegionOpening1.Dispose();
|
||
ho_ConnectedRegions3.Dispose();
|
||
ho_SelectedRegions2.Dispose();
|
||
ho_Contours.Dispose();
|
||
ho_ContoursSplit1.Dispose();
|
||
ho_SelectedXLD.Dispose();
|
||
ho_UnionContours.Dispose();
|
||
ho_ContCircle.Dispose();
|
||
ho_Cross.Dispose();
|
||
}
|
||
|
||
|
||
|
||
}
|
||
public bool FeatureMatchinFindTwoCirCle(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
var lastExposureTime = Camera.ExposureTime;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
var RM = VEI.MyRectangleModel;
|
||
bool pipeiOK = false;
|
||
if (RM == null || RM.ID <= 0)
|
||
{
|
||
ShowText("请选择测试项目", "red", 20);
|
||
return pipeiOK;
|
||
}
|
||
|
||
HObject ho_ImageReduced, ho_ImageScaled;
|
||
|
||
HTuple hv_Row = new HTuple(), hv_Column = new HTuple(), hv_Parameter;
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageScaled);
|
||
|
||
try
|
||
{
|
||
//1,获取图像
|
||
if (newImage && !GetImage(RM))
|
||
{
|
||
return pipeiOK;
|
||
}
|
||
|
||
//截取矩形选框中的图像
|
||
|
||
List<V_Piont> list = new List<V_Piont>();
|
||
bool res = FindTwoCirCle(RM);
|
||
|
||
if (res)
|
||
{
|
||
|
||
//读取已标定文件
|
||
if (RM.ReadCalibrationPar(Camera.CamName))
|
||
{
|
||
HTuple WordRow = null, WordColumn = null, hv_RefRow, hv_RefColumn;
|
||
|
||
|
||
//像素坐标转换成世界坐标
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, BigCirClePix.Y, BigCirClePix.X, out HTuple bigY, out HTuple bigX);
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, SmallCirClePix.Y, SmallCirClePix.X, out HTuple smallY, out HTuple smallX);
|
||
BigCirCle = new MyPoint();
|
||
BigCirCle.X = bigX.D;
|
||
BigCirCle.Y = bigY.D;
|
||
SmallCirCle = new MyPoint();
|
||
|
||
SmallCirCle.X = smallX.D;
|
||
SmallCirCle.Y = smallY.D;
|
||
|
||
|
||
ShowText("大圆中心" + " X:" + BigCirCle.X + ", Y:" + BigCirCle.Y + " ", "green");
|
||
ShowText("小圆中心" + " X:" + SmallCirCle.X + ", Y:" + SmallCirCle.Y, "green", 20, 2);
|
||
|
||
|
||
pipeiOK = true;
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
ShowText("大圆中心像素坐标" + " X:" + BigCirClePix.X + ", Y:" + BigCirClePix.Y, "green", 20);
|
||
ShowText("小圆中心像素坐标" + " X:" + SmallCirClePix.X + ", Y:" + SmallCirClePix.Y, "green", 20, 2);
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
pipeiOK = false;
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
|
||
ho_ImageReduced.Dispose();
|
||
ho_ImageScaled.Dispose();
|
||
|
||
return pipeiOK;
|
||
}
|
||
|
||
public void CreateTwoCircleModel(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
var lastExposureTime = Camera.ExposureTime;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
var RM = VEI.MyRectangleModel;
|
||
if (CreateModeling)
|
||
{
|
||
MyMessageBox.Show("当前已处于编辑状态,请完成之前的所有操作");
|
||
return;
|
||
}
|
||
|
||
if (MyMessageBox.Show("你确定要编辑模型吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Negative)
|
||
{
|
||
return;
|
||
}
|
||
|
||
HTuple hv_Parameter;
|
||
HObject ho_ImageReduced, ho_ImageScaled;
|
||
|
||
//1,获取图像
|
||
if (!GetImage())
|
||
{
|
||
return;
|
||
}
|
||
|
||
|
||
//去畸变
|
||
//DeDistortion();
|
||
|
||
CreateModeling = true;
|
||
//1,绘制区域模型
|
||
DrawArea(Ho_Image, RM);
|
||
RM.Instantiation();
|
||
|
||
//2,绘制ROI
|
||
DrawROI(RM);
|
||
//3、寻找ROI特征
|
||
;
|
||
|
||
//bool bb
|
||
// = FindTwoCirCle( RM );
|
||
|
||
//if (!bb)
|
||
//{
|
||
// MyMessageBox.Show("未能找到明显特征区域");
|
||
// CreateModeling = false;
|
||
// return;
|
||
//}
|
||
|
||
if (MessageDialogResult.Affirmative == MyMessageBox.Show("模板设置完成是否保存?", "提示", MessageDialogStyle.AffirmativeAndNegative))
|
||
{
|
||
|
||
|
||
RM.Instantiation();
|
||
RM.MyROI.Initialize();
|
||
|
||
if (!SaveAll(RM))
|
||
{
|
||
MyMessageBox.Show("保存失败");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
CreateModeling = false;
|
||
|
||
|
||
|
||
}
|
||
public bool FeatureMatchingCirCle2(VisualEngineeringItems VEI, bool newImage = true)
|
||
{
|
||
VEI.ExposureTime = VEI.ExposureTime > 0 ? VEI.ExposureTime : 5000;
|
||
var lastExposureTime = Camera.ExposureTime;
|
||
Camera.ExposureTime = VEI.ExposureTime;
|
||
var RM = VEI.MyRectangleModel;
|
||
bool pipeiOK = false;
|
||
if (RM == null || RM.ID <= 0)
|
||
{
|
||
ShowText("请选择测试项目", "red", 20);
|
||
return pipeiOK;
|
||
}
|
||
|
||
HObject ho_ImageReduced, ho_ImageScaled;
|
||
|
||
HTuple hv_Row = new HTuple(), hv_Column = new HTuple(), hv_Parameter;
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageScaled);
|
||
|
||
try
|
||
{
|
||
//1,获取图像
|
||
if (newImage && !GetImage(RM))
|
||
{
|
||
return pipeiOK;
|
||
}
|
||
|
||
|
||
//// 加深图像反差 黑的更黑 白的更白
|
||
// if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
// {
|
||
// HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
// HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
// HOperatorSet.Rgb1ToGray(Ho_Image, out HObject ho_GrayImage);
|
||
// HOperatorSet.ScaleImage(ho_GrayImage, out ho_ImageScaled, hv_Mult, hv_Add);
|
||
|
||
// }
|
||
// else
|
||
// {
|
||
// ho_ImageScaled = Ho_Image.Clone();
|
||
// }
|
||
|
||
|
||
// ShowObj(ho_ImageScaled);
|
||
|
||
RM.Instantiation();
|
||
//截取矩形选框中的图像
|
||
HOperatorSet.ReduceDomain(Ho_Image, RM.ho_RectangleModel, out ho_ImageReduced);
|
||
List<V_Piont> list = new List<V_Piont>();
|
||
bool res = FindCircle2(ho_ImageReduced, RM, out list);
|
||
|
||
if (res)
|
||
{
|
||
|
||
int a = 0;
|
||
//V_Piont p = new V_Piont();
|
||
//foreach (var item in hv_Parameter.ToDArr())
|
||
//{
|
||
// if (a == 0)
|
||
// {
|
||
// p = new V_Piont() { hv_RefRow = item };
|
||
// a++;
|
||
// }
|
||
// else if (a == 1)
|
||
// {
|
||
// p.hv_RefColumn = item;
|
||
// a++;
|
||
// }
|
||
// else if (a == 2)
|
||
// {
|
||
// a = 0;
|
||
// list.Add(p);
|
||
// }
|
||
|
||
//}
|
||
CircleCount = list.Count;
|
||
|
||
//读取已标定文件
|
||
if (RM.ReadCalibrationPar(Camera.CamName))
|
||
{
|
||
HTuple WordRow = null, WordColumn = null, hv_RefRow, hv_RefColumn;
|
||
|
||
a = 0;
|
||
|
||
//foreach (var item in list)
|
||
//{
|
||
// HOperatorSet.GenCrossContourXld(out ho_Cross, item.hv_RefRow, item.hv_RefColumn, 60, 0);
|
||
// ShowObj(ho_Cross, "green");
|
||
|
||
// //像素坐标转换成世界坐标
|
||
// HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, item.hv_RefRow, item.hv_RefColumn, out WordRow, out WordColumn);
|
||
// HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, RM.LocateList[a].hv_RefRow, RM.LocateList[a].hv_RefColumn, out hv_RefRow, out hv_RefColumn);
|
||
// CurrLocationPoint = new MyPoint();
|
||
// CurrLocationPoint.Y = Math.Round(WordRow.D - hv_RefRow.D, 4);
|
||
// CurrLocationPoint.X = Math.Round(WordColumn.D - hv_RefColumn.D, 4);
|
||
// RM.LocateList[a].DeviationY = CurrLocationPoint.Y;
|
||
// RM.LocateList[a].DeviationX = CurrLocationPoint.X;
|
||
// a++;
|
||
// ShowText(a + " X:" + CurrLocationPoint.X + ", Y:" + CurrLocationPoint.Y, item.hv_RefRow + 20, item.hv_RefColumn + 20, "green", 20);
|
||
|
||
//}
|
||
|
||
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, list[0].hv_RefRow, list[0].hv_RefColumn, 600, 0);
|
||
ShowObj(ho_Cross, "green");
|
||
|
||
//像素坐标转换成世界坐标
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, list[0].hv_RefRow, list[0].hv_RefColumn, out WordRow, out WordColumn);
|
||
HOperatorSet.AffineTransPoint2d(RM.hv_JiuDianCalibrationPar, RM.LocateList[0].hv_RefRow, RM.LocateList[0].hv_RefColumn, out hv_RefRow, out hv_RefColumn);
|
||
CurrPoint = new MyPoint() { X = Math.Round(WordColumn.D, 4), Y = Math.Round(WordRow.D, 4) };
|
||
|
||
CurrOffs = new MyPoint();
|
||
CurrOffs.X = Math.Round(WordColumn.D - hv_RefColumn.D, 4);
|
||
CurrOffs.Y = Math.Round(WordRow.D - hv_RefRow.D, 4);
|
||
|
||
|
||
|
||
CurrLocationPoint = new MyPoint();
|
||
CurrLocationPoint.X = Math.Round(hv_RefColumn.D, 4);
|
||
CurrLocationPoint.Y = Math.Round(hv_RefRow.D, 4);
|
||
|
||
|
||
ShowText("绝对" + " X:" + CurrPoint.X + ", Y:" + CurrPoint.Y + " ", "green");
|
||
ShowText("基准" + " X:" + CurrLocationPoint.X + ", Y:" + CurrLocationPoint.Y, "green", 20, 2);
|
||
ShowText("偏移" + " X:" + CurrOffs.X + ", Y:" + CurrOffs.Y, "green", 20, 4);
|
||
|
||
|
||
pipeiOK = true;
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
// ShowText("像素坐标" + " X:" + CurrPixPoint.X + ", Y:" + CurrPixPoint.Y, "green", 20);
|
||
}
|
||
|
||
|
||
}
|
||
else
|
||
{
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
pipeiOK = false;
|
||
ShowTextPer("没有找到匹配的特征", "red");
|
||
}
|
||
|
||
ho_ImageReduced.Dispose();
|
||
ho_ImageScaled.Dispose();
|
||
|
||
return pipeiOK;
|
||
}
|
||
#endregion
|
||
|
||
#region 保存参数
|
||
|
||
/// <summary>
|
||
/// 更新区域模型
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
/// <returns></returns>
|
||
public bool SaveRM(V_RectangleModel RM)
|
||
{
|
||
bool bl = false;
|
||
if (RM.ID > 0)
|
||
{
|
||
if (Vdal.UpdateRectangleModel(RM) > 0)
|
||
{
|
||
bl = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Vdal.AddRectangleModel(RM) > 0)
|
||
{
|
||
bl = true;
|
||
RM = Vdal.GetRectangleModel(RM.VeiID, RM.AreaType);
|
||
|
||
}
|
||
}
|
||
return bl;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新ROI
|
||
/// </summary>
|
||
/// <param name="ROI"></param>
|
||
/// <returns></returns>
|
||
public bool SaveROI(V_ROI ROI)
|
||
{
|
||
bool bl = false;
|
||
if (ROI.ID > 0)
|
||
{
|
||
if (Vdal.UpdateROI(ROI) > 0)
|
||
{
|
||
bl = true;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (Vdal.AddRectangleROI(ROI) > 0)
|
||
{
|
||
ROI = Vdal.GetROI(ROI.ModelID, ROI.ROIType);
|
||
|
||
bl = true;
|
||
}
|
||
}
|
||
return bl;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存所有参数
|
||
/// </summary>
|
||
/// <param name="obj"></param>
|
||
public bool SaveAll(V_RectangleModel RM)
|
||
{
|
||
bool bl = false;
|
||
|
||
if (Vdal.UpdateRectangleModel(RM) > 0)
|
||
{
|
||
RM.MyROI.ModelID = RM.ID;
|
||
if (Vdal.UpdateROI(RM.MyROI) > 0)
|
||
{
|
||
bl = true;
|
||
}
|
||
}
|
||
|
||
return bl;
|
||
}
|
||
#endregion
|
||
|
||
#region 图像显示方法
|
||
/// <summary>
|
||
/// 图像显示队列集合
|
||
/// </summary>
|
||
public List<HObject> HobjectList { get; set; }
|
||
/// <summary>
|
||
/// 显示内容
|
||
/// </summary>
|
||
public void ShowObj(HObject Hobj)
|
||
{
|
||
try
|
||
{
|
||
if (HobjectIsNull(Hobj))
|
||
{
|
||
return;
|
||
}
|
||
// HOperatorSet.SetSystem("flush_graphic", "false");
|
||
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.DispObj(Hobj, this.HWindowWPF.HalconWindow);
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.DispObj(Hobj, this.HWindowWPF2.HalconWindow);
|
||
}
|
||
//如果是连续采图 则显示十字准星
|
||
if (ContinuousAcquisition)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF.HalconWindow, "green");
|
||
HOperatorSet.DispObj(ho_Cross, this.HWindowWPF.HalconWindow);
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF2.HalconWindow, "green");
|
||
HOperatorSet.DispObj(ho_Cross, this.HWindowWPF2.HalconWindow);
|
||
}
|
||
}
|
||
// HOperatorSet.SetSystem("flush_graphic", "true");
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 显示内容
|
||
/// </summary>
|
||
/// <param name="Hobj"></param>
|
||
/// <param name="hv_Color"></param>
|
||
public void ShowObj(HObject Hobj, string hv_Color)
|
||
{
|
||
try
|
||
{
|
||
if (HobjectIsNull(Hobj))
|
||
{
|
||
return;
|
||
}
|
||
HOperatorSet.SetSystem("flush_graphic", "false");
|
||
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(Hobj, this.HWindowWPF.HalconWindow);
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(Hobj, this.HWindowWPF2.HalconWindow);
|
||
}
|
||
|
||
//如果是连续采图 则显示十字准星
|
||
if (ContinuousAcquisition)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(ho_Cross, this.HWindowWPF.HalconWindow);
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(ho_Cross, this.HWindowWPF2.HalconWindow);
|
||
}
|
||
}
|
||
|
||
HOperatorSet.SetSystem("flush_graphic", "true");
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 显示内容
|
||
/// </summary>
|
||
/// <param name="Hobj"></param>
|
||
/// <param name="hv_Color"></param>
|
||
public void ShowObj(HObject Hobj, int hv_Color)
|
||
{
|
||
try
|
||
{
|
||
if (HobjectIsNull(Hobj))
|
||
{
|
||
return;
|
||
}
|
||
HOperatorSet.SetSystem("flush_graphic", "false");
|
||
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(Hobj, this.HWindowWPF.HalconWindow);
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(Hobj, this.HWindowWPF2.HalconWindow);
|
||
}
|
||
|
||
//如果是连续采图 则显示十字准星
|
||
if (ContinuousAcquisition)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(ho_Cross, this.HWindowWPF.HalconWindow);
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
SetColored(hv_Color);
|
||
HOperatorSet.DispObj(ho_Cross, this.HWindowWPF2.HalconWindow);
|
||
}
|
||
}
|
||
|
||
HOperatorSet.SetSystem("flush_graphic", "true");
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清空显示控件内的所有内容
|
||
/// </summary>
|
||
public void ClearWindowAndData()
|
||
{
|
||
try
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.ClearWindow(HWindowWPF.HalconWindow);
|
||
}
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.ClearWindow(HWindowWPF2.HalconWindow);
|
||
}
|
||
HobjectList = new List<HObject>();
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除需要显示的队列数据
|
||
/// </summary>
|
||
public void ClearObjData()
|
||
{
|
||
if (HobjectList.Count > 0)
|
||
{
|
||
HobjectList = new List<HObject>();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷新显示
|
||
/// </summary>
|
||
public void RefeshWindow()
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HWindowWPF.HalconWindow.ClearWindow();
|
||
}
|
||
|
||
foreach (HObject hobj in HobjectList)
|
||
{
|
||
HOperatorSet.DispObj(hobj, this.HWindowWPF.HalconWindow);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 显示文本信息
|
||
|
||
public void ShowText(HTuple hv_String, HTuple hv_Row, HTuple hv_Column, string hv_Color, int fontSize = 20, int number = 1)
|
||
{
|
||
SetFont("楷体", fontSize, "true", "false");
|
||
hv_Row = hv_Row + 80 * (number - 1);
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF.HalconWindow, hv_Color);
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF.HalconWindow, hv_Row, hv_Column);
|
||
|
||
HOperatorSet.WriteString(HWindowWPF.HalconWindow, str);
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF.HalconWindow, hv_Row, hv_Column);
|
||
HOperatorSet.WriteString(HWindowWPF.HalconWindow, hv_String);
|
||
}
|
||
}
|
||
|
||
try
|
||
{
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF2.HalconWindow, hv_Color);
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF2.HalconWindow, hv_Row, hv_Column);
|
||
|
||
HOperatorSet.WriteString(HWindowWPF2.HalconWindow, str);
|
||
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF2.HalconWindow, hv_Row, hv_Column);
|
||
HOperatorSet.WriteString(HWindowWPF2.HalconWindow, hv_String);
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 显示文本信息
|
||
/// </summary>
|
||
/// <param name="hv_WindowHandle"></param>
|
||
/// <param name="hv_String"></param>
|
||
/// <param name="hv_Color"></param>
|
||
public void ShowText(HTuple hv_String, string hv_Color, int fontSize = 20, int number = 1)
|
||
{
|
||
SetFont("楷体", fontSize, "true", "false");
|
||
HTuple hv_Row = 12 + 80 * (number - 1);
|
||
HTuple hv_Column = 12;
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF.HalconWindow, hv_Color);
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF.HalconWindow, hv_Row, hv_Column);
|
||
|
||
HOperatorSet.WriteString(HWindowWPF.HalconWindow, str);
|
||
hv_Row = hv_Row + 80;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF.HalconWindow, hv_Row, hv_Column);
|
||
HOperatorSet.WriteString(HWindowWPF.HalconWindow, hv_String);
|
||
}
|
||
}
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF2.HalconWindow, hv_Color);
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF2.HalconWindow, hv_Row, hv_Column);
|
||
|
||
HOperatorSet.WriteString(HWindowWPF2.HalconWindow, str);
|
||
hv_Row = hv_Row + 80;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.SetTposition(HWindowWPF2.HalconWindow, hv_Row, hv_Column);
|
||
HOperatorSet.WriteString(HWindowWPF2.HalconWindow, hv_String);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示文本框文本
|
||
/// </summary>
|
||
public void ShowTextPer(HTuple hv_String, double hv_Row, double hv_Column, HTuple hv_Color)
|
||
{
|
||
SetFont("楷体", 30, "true", "false");
|
||
HTuple hv_GenParamName = new HTuple(), hv_GenParamValue = new HTuple();
|
||
hv_Row = hv_Row <= 0 ? 12 : hv_Row;
|
||
hv_Column = hv_Column <= 0 ? 12 : hv_Column;
|
||
|
||
|
||
//不显示边框
|
||
hv_GenParamName = "shadow";
|
||
hv_GenParamValue = "false";
|
||
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF.HalconWindow, str, "window", hv_Row, hv_Column, hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
hv_Row = hv_Row + 80;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF.HalconWindow, hv_String, "window", hv_Row, hv_Column, hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
}
|
||
}
|
||
|
||
|
||
try
|
||
{
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF2.HalconWindow, str, "window", hv_Row, hv_Column, hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
hv_Row = hv_Row + 80;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF2.HalconWindow, hv_String, "window", hv_Row, hv_Column, hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
|
||
////不显示文本框
|
||
//hv_GenParamName = "box";
|
||
//hv_GenParamValue = "false";
|
||
//HOperatorSet.DispText(HWindowWPF.HalconWindow, "测试", "window", "top", "left", "red", hv_GenParamName, hv_GenParamValue);
|
||
|
||
////背景色 蓝色 不显示边框
|
||
//hv_GenParamName = "box_color";
|
||
//hv_GenParamValue = "blue";
|
||
//hv_GenParamName = hv_GenParamName.TupleConcat("shadow");
|
||
//hv_GenParamValue = hv_GenParamValue.TupleConcat("false");
|
||
|
||
//HOperatorSet.DispText(HWindowWPF.HalconWindow, "测试", "window", 200, 200, "red", hv_GenParamName, hv_GenParamValue);
|
||
|
||
////背景色 蓝色 边框绿色
|
||
//hv_GenParamName = "box_color";
|
||
//hv_GenParamValue = "blue";
|
||
//hv_GenParamName = hv_GenParamName.TupleConcat("shadow_color");
|
||
//hv_GenParamValue = hv_GenParamValue.TupleConcat("green");
|
||
//HOperatorSet.DispText(HWindowWPF.HalconWindow, "测试", "window", 300, 300, "red", hv_GenParamName, hv_GenParamValue);
|
||
}
|
||
/// <summary>
|
||
/// 显示文本框文本
|
||
/// </summary>
|
||
/// <param name="hv_String"></param>
|
||
/// <param name="hv_Color"></param>
|
||
public void ShowTextPer(HTuple hv_String, HTuple hv_Color)
|
||
{
|
||
SetFont("楷体", 30, "true", "false");
|
||
HTuple hv_GenParamName = new HTuple(), hv_GenParamValue = new HTuple();
|
||
|
||
//不显示边框
|
||
hv_GenParamName = "shadow";
|
||
hv_GenParamValue = "false";
|
||
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF.HalconWindow, str, "window", "top", "left", hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
hv_Row = hv_Row + 80;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF.HalconWindow, hv_String, "window", 12, 12, hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
}
|
||
}
|
||
|
||
try
|
||
{
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
if (hv_String.Length > 1)
|
||
{
|
||
foreach (string str in hv_String.ToSArr())
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF2.HalconWindow, str, "window", "top", "left", hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
hv_Row = hv_Row + 80;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
HOperatorSet.DispText(HWindowWPF2.HalconWindow, hv_String, "window", 12, 12, hv_Color, hv_GenParamName, hv_GenParamValue);
|
||
}
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
|
||
#region 设置字体
|
||
/// <summary>
|
||
/// 设置字体
|
||
/// </summary>
|
||
/// <param name="hv_Font">字体</param>
|
||
/// <param name="hv_Size">字体大小</param>
|
||
/// <param name="hv_Bold">是否粗体</param>
|
||
/// <param name="hv_Slant">是否倾斜</param>
|
||
public void SetFont(string hv_Font, int hv_Size, string hv_Bold, string hv_Slant)
|
||
{
|
||
try
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HTuple hv_OS = null, hv_Fonts = new HTuple();
|
||
string hv_Style = "";
|
||
string FontStyle = "";
|
||
HTuple hv_FontList = null;
|
||
HOperatorSet.QueryFont(HWindowWPF.HalconWindow, out hv_FontList);//获取系统所有字体
|
||
HOperatorSet.GetSystem("operating_system", out hv_OS); //获取系统字体
|
||
|
||
if (hv_FontList.ToSArr().Contains(hv_Font))
|
||
{
|
||
FontStyle = hv_Font;
|
||
}
|
||
else
|
||
{
|
||
FontStyle = hv_FontList[0];
|
||
}
|
||
|
||
FontStyle = FontStyle + "-";
|
||
//字体是否需要倾斜
|
||
if (hv_Bold == "true")
|
||
{
|
||
hv_Style = hv_Style + "Bold";
|
||
}
|
||
|
||
if (hv_Slant == "true")
|
||
{
|
||
hv_Style = hv_Style + "Italic";
|
||
}
|
||
if (hv_Style == "")
|
||
{
|
||
hv_Style = "Normal";
|
||
}
|
||
FontStyle = FontStyle + hv_Style;
|
||
FontStyle = FontStyle + "-";
|
||
|
||
if (hv_Size <= 0)
|
||
{
|
||
hv_Size = 16;
|
||
}
|
||
if (hv_OS.ToString().Substring(0, 2) == "Win")
|
||
{
|
||
hv_Size = (int)(1.13677 * hv_Size);
|
||
}
|
||
|
||
|
||
FontStyle = FontStyle + hv_Size;
|
||
|
||
HOperatorSet.SetFont(HWindowWPF.HalconWindow, FontStyle);
|
||
}
|
||
|
||
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HTuple hv_OS = null, hv_Fonts = new HTuple();
|
||
string hv_Style = "";
|
||
string FontStyle = "";
|
||
HTuple hv_FontList = null;
|
||
HOperatorSet.QueryFont(HWindowWPF2.HalconWindow, out hv_FontList);//获取系统所有字体
|
||
HOperatorSet.GetSystem("operating_system", out hv_OS); //获取系统字体
|
||
|
||
if (hv_FontList.ToSArr().Contains(hv_Font))
|
||
{
|
||
FontStyle = hv_Font;
|
||
}
|
||
else
|
||
{
|
||
FontStyle = hv_FontList[0];
|
||
}
|
||
|
||
FontStyle = FontStyle + "-";
|
||
//字体是否需要倾斜
|
||
if (hv_Bold == "true")
|
||
{
|
||
hv_Style = hv_Style + "Bold";
|
||
}
|
||
|
||
if (hv_Slant == "true")
|
||
{
|
||
hv_Style = hv_Style + "Italic";
|
||
}
|
||
if (hv_Style == "")
|
||
{
|
||
hv_Style = "Normal";
|
||
}
|
||
FontStyle = FontStyle + hv_Style;
|
||
FontStyle = FontStyle + "-";
|
||
|
||
if (hv_Size <= 0)
|
||
{
|
||
hv_Size = 16;
|
||
}
|
||
if (hv_OS.ToString().Substring(0, 2) == "Win")
|
||
{
|
||
hv_Size = (int)(1.13677 * hv_Size);
|
||
}
|
||
|
||
|
||
FontStyle = FontStyle + hv_Size;
|
||
|
||
HOperatorSet.SetFont(HWindowWPF2.HalconWindow, FontStyle);
|
||
}
|
||
|
||
|
||
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
throw;
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
|
||
#endregion
|
||
|
||
#region 设置窗体前景色
|
||
/// <summary>
|
||
/// 设置窗体前景色
|
||
/// </summary>
|
||
public void SetColored(string hv_Color)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF.HalconWindow, hv_Color);
|
||
}
|
||
try
|
||
{
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColor(HWindowWPF2.HalconWindow, hv_Color);
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置窗体前景色
|
||
/// </summary>
|
||
/// <param name="hv_Color"></param>
|
||
public void SetColored(int hv_Color)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
|
||
HOperatorSet.SetColored(HWindowWPF.HalconWindow, hv_Color);
|
||
|
||
}
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetColored(HWindowWPF2.HalconWindow, hv_Color);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置画笔样式(填充模式 "fill" 边框模式:"margin")
|
||
/// <summary>
|
||
/// 设置画笔样式(填充模式 "fill" 边框模式:"margin")
|
||
/// </summary>
|
||
/// <param name="DrawStyle"></param>
|
||
public void SetDraw(string DrawStyle)
|
||
{
|
||
if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetDraw(HWindowWPF.HalconWindow, DrawStyle);
|
||
}
|
||
try
|
||
{
|
||
if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
{
|
||
HOperatorSet.SetDraw(HWindowWPF2.HalconWindow, DrawStyle);
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 设置工状态光源亮度
|
||
DateTime tempTime;
|
||
/// <summary>
|
||
/// 设置工状态光源亮度
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public void SetLight(V_RectangleModel RM)
|
||
{
|
||
try
|
||
{
|
||
if (LightCOM == null)
|
||
{
|
||
return;
|
||
}
|
||
if (RM.PassagewayBrightness1 > 0)
|
||
{
|
||
LightCOM.Send("SA" + string.Format("{0:d3}", RM.PassagewayBrightness1) + "#");
|
||
}
|
||
if (RM.PassagewayBrightness2 > 0)
|
||
{
|
||
LightCOM.Send("SB" + string.Format("{0:d3}", RM.PassagewayBrightness2) + "#");
|
||
}
|
||
if (RM.PassagewayBrightness3 > 0)
|
||
{
|
||
LightCOM.Send("SC" + string.Format("{0:d3}", RM.PassagewayBrightness3) + "#");
|
||
}
|
||
if (RM.PassagewayBrightness4 > 0)
|
||
{
|
||
LightCOM.Send("SD" + string.Format("{0:d3}", RM.PassagewayBrightness4) + "#");
|
||
}
|
||
tempTime = DateTime.Now;
|
||
|
||
while (true)
|
||
{
|
||
if (DateTime.Now > tempTime.AddMilliseconds(200))
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowTextPer("光源设置失败" + ex.Message, "red");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 关闭已设置的光源状态
|
||
/// <summary>
|
||
/// 关闭已设置的光源状态
|
||
/// </summary>
|
||
/// <param name="RM"></param>
|
||
public void CloseSetLight(V_RectangleModel RM)
|
||
{
|
||
try
|
||
{
|
||
if (LightCOM == null)
|
||
{
|
||
return;
|
||
}
|
||
if (RM.PassagewayBrightness1 > 0)
|
||
{
|
||
LightCOM.Send("SA" + string.Format("{0:d3}", 0) + "#");
|
||
}
|
||
if (RM.PassagewayBrightness2 > 0)
|
||
{
|
||
LightCOM.Send("SB" + string.Format("{0:d3}", 0) + "#");
|
||
}
|
||
if (RM.PassagewayBrightness3 > 0)
|
||
{
|
||
LightCOM.Send("SC" + string.Format("{0:d3}", 0) + "#");
|
||
}
|
||
if (RM.PassagewayBrightness4 > 0)
|
||
{
|
||
LightCOM.Send("SD" + string.Format("{0:d3}", 0) + "#");
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ShowTextPer("光源设置失败" + ex.Message, "red");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 记录异常信息
|
||
|
||
byte[] data { get; set; }
|
||
|
||
/// <summary>
|
||
/// 文件夹路径
|
||
/// </summary>
|
||
string path { get; set; }
|
||
/// <summary>
|
||
/// 文件路径
|
||
/// </summary>
|
||
string paths { get; set; }
|
||
/// <summary>
|
||
/// 记录信息对象
|
||
/// </summary>
|
||
RecordInfo info { get; set; }
|
||
/// <summary>
|
||
/// 打开的文件流对象
|
||
/// </summary>
|
||
FileStream FS { get; set; }
|
||
|
||
/// <summary>
|
||
/// 异常信息集合
|
||
/// </summary>
|
||
public ObservableCollection<RecordInfo> ExcepList { get; set; }
|
||
/// <summary>
|
||
/// 记录日志信息到文件
|
||
/// </summary>
|
||
/// <param name="showMag">描述文字</param>
|
||
/// <param name="por">操作建议</param>
|
||
public void RecordLog(string showMag, string por)
|
||
{
|
||
try
|
||
{
|
||
info = new RecordInfo() { Number = ExcepList.Count() + 1, HappenTime = DateTime.Now, Describe = showMag, Proposal = por };
|
||
//异步新增项 这是微软的BUG 只能这么麻烦了
|
||
HWindowWPF.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ParameterizedThreadStart(AddItem), info);
|
||
|
||
path = @"E:\\SystemLog";
|
||
paths = @"E:\\SystemLog\" + DateTime.Now.ToString("D") + ".txt";
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
|
||
//打开或创建文件
|
||
FS = File.Open(paths, FileMode.Append);
|
||
|
||
//获得字节数组
|
||
|
||
data = System.Text.Encoding.Default.GetBytes(info.Number + "-" + info.HappenTime.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "-" + info.Describe + "-" + info.Proposal + "\r\n");
|
||
//开始写入
|
||
FS.Write(data, 0, data.Length);
|
||
//清空缓冲区、关闭流
|
||
FS.Flush();
|
||
FS.Close();
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
void AddItem(object info)
|
||
{
|
||
ExcepList.Add((RecordInfo)info);
|
||
}
|
||
#endregion
|
||
|
||
#region 保存生产过程的图片
|
||
/// <summary>
|
||
/// 保存生产过程的图片
|
||
/// </summary>
|
||
/// <param name="OKorNG"></param>
|
||
/// <param name="ImageName">图片名称</param>
|
||
public void SaveImagePro(bool OKorNG, string ImageName)
|
||
{
|
||
try
|
||
{
|
||
if (Camera.SaveImangeOK && OKorNG)
|
||
{
|
||
//HImage imagetemp = HWindowWPF2.HalconWindow.DumpWindowImage(); //视觉窗口图像
|
||
//创建文件夹
|
||
if (!Directory.Exists(@"D:/ImageOK/" + Camera.CamName + "/"))
|
||
{
|
||
Directory.CreateDirectory(@"D:/ImageOK/" + Camera.CamName + "/");
|
||
}
|
||
string name = string.IsNullOrEmpty(ImageName) ? DateTime.Now.ToString("yyyyMMddHHmmss") : ImageName + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||
string filePath = @"D:/ImageOK/" + Camera.CamName + "/" + name + ".bmp";
|
||
|
||
//HOperatorSet.WriteImage(imagetemp, "jpg", 0, filePath);
|
||
HOperatorSet.WriteImage(Ho_Image, "bmp", 0, filePath);
|
||
//imagetemp.Dispose();
|
||
}
|
||
else if (Camera.SaveImangeNG && !OKorNG)
|
||
{
|
||
// HImage imagetemp = HWindowWPF2.HalconWindow.DumpWindowImage(); //视觉窗口图像
|
||
//创建文件夹
|
||
if (!Directory.Exists(@"D:/ImageNG/" + Camera.CamName + "/"))
|
||
{
|
||
Directory.CreateDirectory(@"D:/ImageNG/" + Camera.CamName + "/");
|
||
}
|
||
string name = string.IsNullOrEmpty(ImageName) ? DateTime.Now.ToString("yyyyMMddHHmmss") : ImageName + "-" + DateTime.Now.ToString("yyyyMMddHHmmss");
|
||
string filePath = @"D:/ImageNG/" + Camera.CamName + "/" + name + ".bmp";
|
||
|
||
//HOperatorSet.WriteImage(imagetemp, "jpg", 0, filePath);
|
||
// imagetemp.Dispose();
|
||
HOperatorSet.WriteImage(Ho_Image, "bmp", 0, filePath);
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存图像
|
||
/// </summary>
|
||
/// <param name="ImageName">保存图像的名称</param>
|
||
public void SaveImage(string ImageName)
|
||
{
|
||
string path = @"D:/OriginalGraph/" + Camera.CamName + "/" + DateTime.Now.ToString("D") + "/";
|
||
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
|
||
string filePath = path + ImageName + ".bmp"; //图片存放路径 //保存模板图片
|
||
HOperatorSet.WriteImage(Ho_Image, "bmp", 0, filePath);
|
||
}
|
||
#endregion
|
||
|
||
|
||
/// <summary>
|
||
/// 保存压缩图像
|
||
/// </summary>
|
||
/// <param name="ImageName">保存图像的名称</param>
|
||
public void SaveImage2(string ImageName)
|
||
{
|
||
string path = @"D:/MotorInfo/" + Camera.CamName + "/" + DateTime.Now.ToString("D") + "/";
|
||
|
||
//创建文件夹
|
||
if (!Directory.Exists(path))
|
||
{
|
||
Directory.CreateDirectory(path);
|
||
}
|
||
|
||
string filePath = path + ImageName + ".jpeg"; //图片存放路径 //保存模板图片
|
||
HOperatorSet.WriteImage(Ho_Image, "jpeg 60", 0, filePath);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 抓取角点 mode=1 从白到黑:negative mode=2从黑到白 positive
|
||
/// </summary>
|
||
/// <param name="ho_Image"></param>
|
||
/// <param name="mode"></param>
|
||
/// <param name="cp"></param>
|
||
/// <param name="hv_Rowex"></param>
|
||
/// <param name="hv_Columnex"></param>
|
||
/// <param name="hv_Angle"></param>
|
||
/// <param name="hv_Angle1"></param>
|
||
public void FindPoint(HObject ho_Image, V_CornerPoint cp, out HTuple hv_Rowex, out HTuple hv_Columnex, out HTuple hv_Angle, out HTuple hv_Angle1)
|
||
{
|
||
|
||
// Local iconic variables
|
||
|
||
HObject ho_Contour_LeftLine, ho_Contour_UpLine;
|
||
HObject ho_Contours, ho_Cross;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_LinePar_Left_Line = null, hv_LinePar_Up_Line = null;
|
||
HTuple hv_MetrologyHandle_Line = null, hv_Left_Index = null;
|
||
HTuple hv_Up_Index = null, hv_Row1 = null, hv_Column1 = null;
|
||
HTuple hv_Row12 = null, hv_Col12 = null, hv_Row22 = null;
|
||
HTuple hv_Col22 = null, hv_Row52 = null, hv_Col52 = null;
|
||
HTuple hv_Row62 = null, hv_Col62 = null, hv_IsOverlapping = null;
|
||
// Initialize local and output iconic variables
|
||
HOperatorSet.GenEmptyObj(out ho_Contour_LeftLine);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour_UpLine);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours);
|
||
HOperatorSet.GenEmptyObj(out ho_Cross);
|
||
hv_LinePar_Left_Line = new HTuple();
|
||
hv_LinePar_Left_Line = hv_LinePar_Left_Line.TupleConcat(cp.hv_Row1);
|
||
hv_LinePar_Left_Line = hv_LinePar_Left_Line.TupleConcat(cp.hv_Column1);
|
||
hv_LinePar_Left_Line = hv_LinePar_Left_Line.TupleConcat(cp.hv_Row2);
|
||
hv_LinePar_Left_Line = hv_LinePar_Left_Line.TupleConcat(cp.hv_Column2);
|
||
hv_LinePar_Up_Line = new HTuple();
|
||
hv_LinePar_Up_Line = hv_LinePar_Up_Line.TupleConcat(cp.hv_Row11);
|
||
hv_LinePar_Up_Line = hv_LinePar_Up_Line.TupleConcat(cp.hv_Column11);
|
||
hv_LinePar_Up_Line = hv_LinePar_Up_Line.TupleConcat(cp.hv_Row22);
|
||
hv_LinePar_Up_Line = hv_LinePar_Up_Line.TupleConcat(cp.hv_Column22);
|
||
|
||
//从白到黑:negative 从黑到白 positive
|
||
string modestr = "negative";
|
||
if (cp.Model == 2)
|
||
{
|
||
modestr = "positive";
|
||
}
|
||
|
||
|
||
|
||
HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle_Line);
|
||
HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandle_Line, "line", hv_LinePar_Left_Line, 5, 5, 1, 10, "min_score", 0.5, out hv_Left_Index);
|
||
HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandle_Line, "line", hv_LinePar_Up_Line, 5, 5, 1, 10, "min_score", 0.5, out hv_Up_Index);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Left_Index, "measure_select", "first");
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Left_Index, "measure_transition", modestr); //从白到黑:negative 从黑到白 positive
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Left_Index, "distance_threshold", 5);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Left_Index, "measure_length1", 200);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Left_Index, "measure_length2", 15);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Left_Index, "num_measures", 20);
|
||
|
||
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Up_Index, "measure_select", "first");
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Up_Index, "measure_transition", modestr); //从白到黑:negative 从黑到白 positive
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Up_Index, "distance_threshold", 5);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Up_Index, "measure_length1", 200);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Up_Index, "measure_length2", 15);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Up_Index, "num_measures", 20);
|
||
|
||
|
||
HOperatorSet.ApplyMetrologyModel(ho_Image, hv_MetrologyHandle_Line);
|
||
|
||
ho_Contour_LeftLine.Dispose();
|
||
HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour_LeftLine, hv_MetrologyHandle_Line, hv_Left_Index, "all", 1.5);
|
||
ho_Contour_UpLine.Dispose();
|
||
HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour_UpLine, hv_MetrologyHandle_Line, hv_Up_Index, "all", 1.5);
|
||
ho_Contours.Dispose();
|
||
HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours, hv_MetrologyHandle_Line, "all", "all", out hv_Row1, out hv_Column1);
|
||
ShowObj(ho_Contours, 12);
|
||
ho_Cross.Dispose();
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row1, hv_Column1, 60, 0);
|
||
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Left_Index, "all", "result_type", "row_begin", out hv_Row12);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Left_Index, "all", "result_type", "column_begin", out hv_Col12);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Left_Index, "all", "result_type", "row_end", out hv_Row22);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Left_Index, "all", "result_type", "column_end", out hv_Col22);
|
||
|
||
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Up_Index, "all", "result_type", "row_begin", out hv_Row52);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Up_Index, "all", "result_type", "column_begin", out hv_Col52);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Up_Index, "all", "result_type", "row_end", out hv_Row62);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Up_Index, "all", "result_type", "column_end", out hv_Col62);
|
||
|
||
|
||
HOperatorSet.ClearMetrologyModel(hv_MetrologyHandle_Line);
|
||
HOperatorSet.IntersectionLines(hv_Row12, hv_Col12, hv_Row22, hv_Col22, hv_Row52, hv_Col52, hv_Row62, hv_Col62, out hv_Rowex, out hv_Columnex, out hv_IsOverlapping);
|
||
HOperatorSet.AngleLx(hv_Row12, hv_Col12, hv_Row22, hv_Col22, out hv_Angle);
|
||
HOperatorSet.AngleLx(hv_Row52, hv_Col52, hv_Row62, hv_Col62, out hv_Angle1);
|
||
|
||
|
||
ShowObj(ho_Contour_LeftLine, "green");
|
||
ShowObj(ho_Contour_UpLine, "green");
|
||
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Rowex, hv_Columnex, 600, 0);
|
||
ShowObj(ho_Cross, "red");
|
||
|
||
//if (HWindowWPF.HalconID.ToInt32() > 0)
|
||
//{
|
||
// HOperatorSet.DispCross(this.HWindowWPF.HalconWindow, hv_Rowex, hv_Columnex, 185, 0);
|
||
//}
|
||
|
||
//if (HWindowWPF2.HalconID.ToInt32() > 0)
|
||
//{
|
||
// HOperatorSet.DispCross(this.HWindowWPF2.HalconWindow, hv_Rowex, hv_Columnex, 185, 0);
|
||
|
||
//}
|
||
// ShowText("像素坐标 X:"+Math.Round( hv_Rowex.D,4)+" Y:"+Math.Round( hv_Columnex.D,4), "green");
|
||
|
||
ho_Contour_LeftLine.Dispose();
|
||
ho_Contour_UpLine.Dispose();
|
||
ho_Contours.Dispose();
|
||
ho_Cross.Dispose();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 抓边缘直线
|
||
/// </summary>
|
||
/// <param name="ho_Image"></param>
|
||
/// <param name="cp"></param>
|
||
/// <param name="hv_Row1"></param>
|
||
/// <param name="hv_Column1"></param>
|
||
/// <param name="hv_Row2"></param>
|
||
/// <param name="hv_Column2"></param>
|
||
/// <param name=""></param>
|
||
public void FindEdgeLine(HObject ho_Image, V_CornerPoint cp, out HTuple hv_Row1, out HTuple hv_Column1, out HTuple hv_Row2, out HTuple hv_Column2, out HTuple hv_Angle)
|
||
{
|
||
// Local iconic variables
|
||
|
||
HObject ho_Contour_Line;
|
||
HObject ho_Contours, ho_Cross;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_LinePar = null;
|
||
HTuple hv_MetrologyHandle_Line = null, hv_Line_Index = null;
|
||
HTuple hv_Row = null, hv_Column = null;
|
||
|
||
|
||
// Initialize local and output iconic variables
|
||
HOperatorSet.GenEmptyObj(out ho_Contour_Line);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours);
|
||
HOperatorSet.GenEmptyObj(out ho_Cross);
|
||
hv_LinePar = new HTuple();
|
||
hv_LinePar = hv_LinePar.TupleConcat(cp.hv_Row1);
|
||
hv_LinePar = hv_LinePar.TupleConcat(cp.hv_Column1);
|
||
hv_LinePar = hv_LinePar.TupleConcat(cp.hv_Row2);
|
||
hv_LinePar = hv_LinePar.TupleConcat(cp.hv_Column2);
|
||
|
||
//从白到黑:negative 从黑到白 positive
|
||
string modestr = "negative";
|
||
if (cp.Model == 2)
|
||
{
|
||
modestr = "positive";
|
||
}
|
||
|
||
HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle_Line);
|
||
HOperatorSet.AddMetrologyObjectGeneric(hv_MetrologyHandle_Line, "line", hv_LinePar, 5, 5, 1, 10, "min_score", 0.5, out hv_Line_Index);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Line_Index, "measure_select", "first");
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Line_Index, "measure_transition", modestr); //从白到黑:negative 从黑到白 positive
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Line_Index, "distance_threshold", 2);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Line_Index, "measure_length1", 200);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Line_Index, "measure_length2", 15);
|
||
HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle_Line, hv_Line_Index, "num_measures", 50);
|
||
|
||
|
||
|
||
HOperatorSet.ApplyMetrologyModel(ho_Image, hv_MetrologyHandle_Line);
|
||
|
||
ho_Contour_Line.Dispose();
|
||
HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour_Line, hv_MetrologyHandle_Line, hv_Line_Index, "all", 1.5);
|
||
|
||
ho_Contours.Dispose();
|
||
HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours, hv_MetrologyHandle_Line, "all", "all", out hv_Row, out hv_Column);
|
||
ho_Cross.Dispose();
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row, hv_Column, 60, 0);
|
||
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Line_Index, "all", "result_type", "row_begin", out hv_Row1);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Line_Index, "all", "result_type", "column_begin", out hv_Column1);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Line_Index, "all", "result_type", "row_end", out hv_Row2);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle_Line, hv_Line_Index, "all", "result_type", "column_end", out hv_Column2);
|
||
|
||
HOperatorSet.ClearMetrologyModel(hv_MetrologyHandle_Line);
|
||
HOperatorSet.AngleLx(hv_Row1, hv_Column1, hv_Row2, hv_Column2, out hv_Angle);
|
||
|
||
ShowObj(ho_Contour_Line, "green");
|
||
|
||
// ShowText("像素坐标 X:"+Math.Round( hv_Rowex.D,4)+" Y:"+Math.Round( hv_Columnex.D,4), "green");
|
||
|
||
ho_Contour_Line.Dispose();
|
||
ho_Contours.Dispose();
|
||
ho_Cross.Dispose();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 找可变矩形1
|
||
/// </summary>
|
||
/// <param name="ho_Image"></param>
|
||
/// <param name="Row"></param>
|
||
/// <param name="Column"></param>
|
||
/// <param name="Angle"></param>
|
||
/// <returns></returns>
|
||
public bool FindRectangle2(HObject ho_Image, V_RectangleModel RM, out HTuple Row, out HTuple Column, out HTuple Angle)
|
||
{
|
||
bool bl = false;
|
||
|
||
HObject ho_Regions;
|
||
HObject ho_RegionOpening1, ho_ConnectedRegions, ho_SelectedRegions;
|
||
HObject ho_Contours2, ho_Rectangle, ho_Contour, ho_Contours1;
|
||
HObject ho_Contour1, ho_Rectangle1, ho_Cross;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_Row = null, hv_Column = null, hv_Phi = null;
|
||
HTuple hv_Length1 = null, hv_Length2 = null, hv_PointOrder2 = null;
|
||
HTuple hv_MetrologyHandle = null, hv_Index1 = null, hv_Row1 = null;
|
||
HTuple hv_Column1 = null, hv_Parameter = null, hv_Area = null;
|
||
HTuple hv_Row2 = null, hv_Column2 = null, hv_PointOrder1 = null;
|
||
// Initialize local and output iconic variables
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_Regions);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours2);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours1);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour1);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle1);
|
||
HOperatorSet.GenEmptyObj(out ho_Cross);
|
||
|
||
Row = 0;
|
||
Column = 0;
|
||
Angle = 0;
|
||
|
||
try
|
||
{
|
||
|
||
//HOperatorSet.MeanImage(ho_Image, out ho_ImageMean, 9, 9);
|
||
//ho_Regions.Dispose();
|
||
HOperatorSet.Threshold(ho_Image, out ho_Regions, RM.MyROI.ThresholdMin, RM.MyROI.ThresholdMax);
|
||
ho_RegionOpening1.Dispose();
|
||
HOperatorSet.OpeningRectangle1(ho_Regions, out ho_RegionOpening1, RM.MyROI.ShapeC_Min, RM.MyROI.ShapeC_Max);
|
||
ho_ConnectedRegions.Dispose();
|
||
HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions);
|
||
ho_SelectedRegions.Dispose();
|
||
HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, (new HTuple("area")).TupleConcat("rectangularity"), "and", (new HTuple(RM.MyROI.ShapeB_Min)).TupleConcat(0.85), (new HTuple(RM.MyROI.ShapeB_Max)).TupleConcat(1));
|
||
|
||
ho_Contours2.Dispose();
|
||
HOperatorSet.GenContourRegionXld(ho_SelectedRegions, out ho_Contours2, "border");
|
||
HOperatorSet.FitRectangle2ContourXld(ho_Contours2, "regression", -1, 0, 0, 3, 2, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2, out hv_PointOrder2);
|
||
ho_Rectangle.Dispose();
|
||
HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2);
|
||
ShowObj(ho_Rectangle, "green");
|
||
|
||
HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);
|
||
HOperatorSet.AddMetrologyObjectRectangle2Measure(hv_MetrologyHandle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2, 30, 2, 3, 30, new HTuple(), new HTuple(), out hv_Index1);
|
||
ho_Contour.Dispose();
|
||
HOperatorSet.GetMetrologyObjectModelContour(out ho_Contour, hv_MetrologyHandle, "all", 1.5);
|
||
ho_Contours1.Dispose();
|
||
HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours1, hv_MetrologyHandle, "all", "all", out hv_Row1, out hv_Column1);
|
||
HOperatorSet.ApplyMetrologyModel(ho_Image, hv_MetrologyHandle);
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type", "all_param", out hv_Parameter);
|
||
ho_Contour1.Dispose();
|
||
HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour1, hv_MetrologyHandle, "all", "all", 1.5);
|
||
|
||
//获取搜寻出来的矩形 这五个参数分别是 Row, Column, Phi, Length1, Length2
|
||
ho_Rectangle1.Dispose();
|
||
HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle1, hv_Parameter.TupleSelect(0), hv_Parameter.TupleSelect(1), hv_Parameter.TupleSelect(2), hv_Parameter.TupleSelect(3), hv_Parameter.TupleSelect(4));
|
||
HOperatorSet.AreaCenterXld(ho_Rectangle1, out hv_Area, out hv_Row2, out hv_Column2, out hv_PointOrder1);
|
||
ho_Cross.Dispose();
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row2, hv_Column2, 90, hv_Parameter.TupleSelect(2));
|
||
|
||
//返回矩形中心点及角度
|
||
Row = hv_Row2;
|
||
Column = hv_Column2;
|
||
Angle = hv_Parameter.TupleSelect(2);
|
||
|
||
bl = true;
|
||
//ShowObj(Ho_Image);
|
||
//ShowObj(ho_Contours1,12);
|
||
ShowObj(ho_Contours1, 12);
|
||
ShowObj(ho_Rectangle1, "green");
|
||
ShowObj(ho_Cross, "green");
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
ho_Regions.Dispose();
|
||
ho_RegionOpening1.Dispose();
|
||
ho_ConnectedRegions.Dispose();
|
||
ho_SelectedRegions.Dispose();
|
||
ho_Contours2.Dispose();
|
||
ho_Rectangle.Dispose();
|
||
ho_Contour.Dispose();
|
||
ho_Contours1.Dispose();
|
||
ho_Contour1.Dispose();
|
||
ho_Rectangle1.Dispose();
|
||
ho_Cross.Dispose();
|
||
|
||
return bl;
|
||
}
|
||
/// <summary>
|
||
/// 找可变矩形2
|
||
/// </summary>
|
||
/// <param name="ho_Image"></param>
|
||
/// <param name="RM"></param>
|
||
/// <param name="Row"></param>
|
||
/// <param name="Column"></param>
|
||
/// <param name="Angle"></param>
|
||
/// <returns></returns>
|
||
public bool FindRectangle2_A(HObject ho_Image, V_RectangleModel RM, out HTuple Row, out HTuple Column, out HTuple Angle)
|
||
{
|
||
bool bl = false;
|
||
|
||
HObject ho_Regions;
|
||
HObject ho_RegionOpening1, ho_ConnectedRegions, ho_SelectedRegions;
|
||
HObject ho_Contours2, ho_Rectangle, ho_Contour, ho_Contours1;
|
||
HObject ho_Contour1, ho_Rectangle1, ho_Cross;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_Row = null, hv_Column = null, hv_Phi = null;
|
||
HTuple hv_Length1 = null, hv_Length2 = null, hv_PointOrder2 = null;
|
||
HTuple hv_Area = null;
|
||
HTuple hv_Row2 = null, hv_Column2 = null, hv_PointOrder1 = null;
|
||
// Initialize local and output iconic variables
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_Regions);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours2);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours1);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour1);
|
||
HOperatorSet.GenEmptyObj(out ho_Rectangle1);
|
||
HOperatorSet.GenEmptyObj(out ho_Cross);
|
||
|
||
Row = 0;
|
||
Column = 0;
|
||
Angle = 0;
|
||
|
||
try
|
||
{
|
||
|
||
//HOperatorSet.MeanImage(ho_Image, out ho_ImageMean, 9, 9);
|
||
//ho_Regions.Dispose();
|
||
HOperatorSet.Threshold(ho_Image, out ho_Regions, RM.MyROI.ThresholdMin, RM.MyROI.ThresholdMax);
|
||
ho_RegionOpening1.Dispose();
|
||
HOperatorSet.OpeningRectangle1(ho_Regions, out ho_RegionOpening1, RM.MyROI.ShapeC_Min, RM.MyROI.ShapeC_Max);
|
||
ho_ConnectedRegions.Dispose();
|
||
HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions);
|
||
ho_SelectedRegions.Dispose();
|
||
HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions, (new HTuple("area")).TupleConcat("rectangularity"), "and", (new HTuple(RM.MyROI.ShapeB_Min)).TupleConcat(0.85), (new HTuple(RM.MyROI.ShapeB_Max)).TupleConcat(1));
|
||
|
||
ho_Contours2.Dispose();
|
||
HOperatorSet.GenContourRegionXld(ho_SelectedRegions, out ho_Contours2, "border");
|
||
HOperatorSet.FitRectangle2ContourXld(ho_Contours2, "regression", -1, 0, 0, 3, 2, out hv_Row, out hv_Column, out hv_Phi, out hv_Length1, out hv_Length2, out hv_PointOrder2);
|
||
ho_Rectangle.Dispose();
|
||
HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2);
|
||
ShowObj(ho_Rectangle, "green");
|
||
|
||
//HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);
|
||
//HOperatorSet.AddMetrologyObjectRectangle2Measure(hv_MetrologyHandle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2, 30, 2, 3, 30, new HTuple(), new HTuple(), out hv_Index1);
|
||
//ho_Contour.Dispose();
|
||
//HOperatorSet.GetMetrologyObjectModelContour(out ho_Contour, hv_MetrologyHandle, "all", 1.5);
|
||
//ho_Contours1.Dispose();
|
||
//HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours1, hv_MetrologyHandle, "all", "all", out hv_Row1, out hv_Column1);
|
||
//HOperatorSet.ApplyMetrologyModel(ho_Image, hv_MetrologyHandle);
|
||
//HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type", "all_param", out hv_Parameter);
|
||
//ho_Contour1.Dispose();
|
||
//HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour1, hv_MetrologyHandle, "all", "all", 1.5);
|
||
|
||
////获取搜寻出来的矩形 这五个参数分别是 Row, Column, Phi, Length1, Length2
|
||
//ho_Rectangle1.Dispose();
|
||
//HOperatorSet.GenRectangle2ContourXld(out ho_Rectangle1, hv_Parameter.TupleSelect(0), hv_Parameter.TupleSelect(1), hv_Parameter.TupleSelect(2), hv_Parameter.TupleSelect(3), hv_Parameter.TupleSelect(4));
|
||
HOperatorSet.AreaCenterXld(ho_Rectangle, out hv_Area, out hv_Row2, out hv_Column2, out hv_PointOrder1);
|
||
ho_Cross.Dispose();
|
||
HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row2, hv_Column2, 60, hv_Phi);
|
||
|
||
//返回矩形中心点及角度
|
||
Row = hv_Row2;
|
||
Column = hv_Column2;
|
||
Angle = hv_Phi;
|
||
|
||
bl = true;
|
||
//ShowObj(Ho_Image);
|
||
//ShowObj(ho_Contours1,12);
|
||
//ShowObj(ho_Contours1, 12);
|
||
ShowObj(ho_Rectangle, "green");
|
||
ShowObj(ho_Cross, "green");
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
|
||
ho_Regions.Dispose();
|
||
ho_RegionOpening1.Dispose();
|
||
ho_ConnectedRegions.Dispose();
|
||
ho_SelectedRegions.Dispose();
|
||
ho_Contours2.Dispose();
|
||
ho_Rectangle.Dispose();
|
||
ho_Contour.Dispose();
|
||
ho_Contours1.Dispose();
|
||
ho_Contour1.Dispose();
|
||
ho_Rectangle1.Dispose();
|
||
ho_Cross.Dispose();
|
||
|
||
return bl;
|
||
}
|
||
/// <summary>
|
||
/// 找圆
|
||
/// </summary>
|
||
/// <param name="ho_Image"></param>
|
||
/// <param name="RM"></param>
|
||
/// <param name="hv_Parameter"></param>
|
||
/// <returns></returns>
|
||
private bool FindCircle(HObject ho_Image, V_RectangleModel RM, out List<V_Piont> PointList)
|
||
{
|
||
bool bl = false;
|
||
HObject ho_GrayImage, ho_ImageReduced;
|
||
HObject ho_Regions, ho_RegionOpening, ho_ConnectedRegions, ho_RegionFillUp;
|
||
HObject ho_SelectedRegions1, ho_Contours, ho_ContCircle, ho_ContoursSplit1, ho_SelectedXLD;
|
||
HObject ho_Contour, ho_Contours1, ho_Contour1, ho_RegionTrans, ho_UnionContours;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_WindowHandle = new HTuple(), hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Radius = new HTuple();
|
||
HTuple hv_StartPhi = new HTuple(), hv_EndPhi = new HTuple();
|
||
HTuple hv_PointOrder = new HTuple(), hv_MetrologyHandle = new HTuple();
|
||
HTuple hv_Index = new HTuple(), hv_Row1 = new HTuple();
|
||
HTuple hv_Column1 = new HTuple();
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_GrayImage);
|
||
HOperatorSet.GenEmptyObj(out ho_ImageReduced);
|
||
HOperatorSet.GenEmptyObj(out ho_Regions);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionOpening);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours);
|
||
HOperatorSet.GenEmptyObj(out ho_ContCircle);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours1);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour1);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
|
||
HOperatorSet.GenEmptyObj(out ho_ContoursSplit1);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedXLD);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionTrans);
|
||
HOperatorSet.GenEmptyObj(out ho_UnionContours);
|
||
|
||
try
|
||
{
|
||
|
||
ho_GrayImage.Dispose();
|
||
HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
|
||
|
||
ho_Regions.Dispose();
|
||
HOperatorSet.Threshold(ho_GrayImage, out ho_Regions, 250, 255);
|
||
ho_ConnectedRegions.Dispose();
|
||
HOperatorSet.Connection(ho_Regions, out ho_ConnectedRegions);
|
||
ho_SelectedRegions1.Dispose();
|
||
HOperatorSet.SelectShapeStd(ho_ConnectedRegions, out ho_SelectedRegions1, "max_area", 70);
|
||
ho_RegionTrans.Dispose();
|
||
HOperatorSet.ShapeTrans(ho_SelectedRegions1, out ho_RegionTrans, "rectangle2");
|
||
ho_ImageReduced.Dispose();
|
||
HOperatorSet.ReduceDomain(ho_GrayImage, ho_RegionTrans, out ho_ImageReduced);
|
||
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
// HOperatorSet.Rgb1ToGray(Ho_Image, out HObject ho_GrayImage);
|
||
HOperatorSet.ScaleImage(ho_ImageReduced, out ho_ImageReduced, hv_Mult, hv_Add);
|
||
|
||
}
|
||
//else
|
||
//{
|
||
// ho_ImageScaled = Ho_Image.Clone();
|
||
//}
|
||
|
||
|
||
//RM.MyROI.Initialize();
|
||
//ho_ImageReduced.Dispose();
|
||
//HOperatorSet.ReduceDomain(ho_GrayImage, RM.MyROI.ho_OutlineROI, out ho_ImageReduced);
|
||
//ClearWindowAndData();
|
||
//ShowObj(ho_ImageReduced);
|
||
//ho_Regions.Dispose();
|
||
HOperatorSet.Threshold(ho_ImageReduced, out ho_Regions, RM.MyROI.ThresholdMin, RM.MyROI.ThresholdMax);
|
||
ho_RegionFillUp.Dispose();
|
||
HOperatorSet.FillUp(ho_Regions, out ho_RegionFillUp);
|
||
ho_RegionOpening.Dispose();
|
||
HOperatorSet.OpeningCircle(ho_RegionFillUp, out ho_RegionOpening, RM.MyROI.ShapeC_Max);
|
||
ho_ConnectedRegions.Dispose();
|
||
HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
|
||
SetDraw("fill");
|
||
ClearWindowAndData();
|
||
ShowObj(ho_ConnectedRegions);
|
||
|
||
ho_SelectedRegions1.Dispose();
|
||
HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions1, (new HTuple("circularity")).TupleConcat("area"), "and", (new HTuple(0.4)).TupleConcat(RM.MyROI.ShapeB_Min), (new HTuple(1)).TupleConcat(RM.MyROI.ShapeB_Max));
|
||
//SetDraw("fill");
|
||
//ClearWindowAndData();
|
||
//ShowObj(ho_SelectedRegions1);
|
||
ho_Contours.Dispose();
|
||
HOperatorSet.GenContourRegionXld(ho_SelectedRegions1, out ho_Contours, "border");
|
||
ho_ContoursSplit1.Dispose();
|
||
HOperatorSet.SegmentContoursXld(ho_Contours, out ho_ContoursSplit1, "lines_circles", 5, 20, 10);
|
||
ho_SelectedXLD.Dispose();
|
||
HOperatorSet.SelectShapeXld(ho_ContoursSplit1, out ho_SelectedXLD, "circularity", "and", 0.2, 1);
|
||
//合并中点在一起的轮廓
|
||
ho_UnionContours.Dispose();
|
||
HOperatorSet.UnionAdjacentContoursXld(ho_SelectedXLD, out ho_UnionContours, 10, 1, "attr_keep");
|
||
HOperatorSet.FitCircleContourXld(ho_UnionContours, "algebraic", -1, 0, 0, 3, 2, out hv_Row, out hv_Column, out hv_Radius, out hv_StartPhi, out hv_EndPhi, out hv_PointOrder);
|
||
ho_ContCircle.Dispose();
|
||
HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column, hv_Radius, 0, 6.28318, "positive", 1);
|
||
|
||
HTuple hv_Area = new HTuple();
|
||
HTuple hv_Row2 = new HTuple();
|
||
HTuple hv_Column2 = new HTuple();
|
||
HTuple hv_PointOrder1 = new HTuple();
|
||
HOperatorSet.AreaCenterXld(ho_ContCircle, out hv_Area, out hv_Row2, out hv_Column2, out hv_PointOrder1);
|
||
//HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);
|
||
//HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, hv_Row, hv_Column, hv_Radius, 30, 1, 1, 5, new HTuple(), new HTuple(), out hv_Index);
|
||
|
||
//ho_Contour.Dispose();
|
||
//HOperatorSet.GetMetrologyObjectModelContour(out ho_Contour, hv_MetrologyHandle, "all", 1.5);
|
||
|
||
//HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours1, hv_MetrologyHandle, "all", "all", out hv_Row1, out hv_Column1);
|
||
//HOperatorSet.ApplyMetrologyModel(Ho_Image, hv_MetrologyHandle);
|
||
|
||
//HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type", "all_param", out hv_Parameter);
|
||
//ho_Contour1.Dispose();
|
||
//HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour1, hv_MetrologyHandle, "all", "all", 1.5);
|
||
//HOperatorSet.ClearMetrologyModel(hv_MetrologyHandle);
|
||
|
||
List<V_Piont> list = new List<V_Piont>();
|
||
|
||
int a = 0;
|
||
foreach (var item in hv_Area.ToDArr())
|
||
{
|
||
V_Piont p = new V_Piont() { hv_RefRow = hv_Row2[a], hv_RefColumn = hv_Column2[a] };
|
||
a++;
|
||
list.Add(p);
|
||
}
|
||
PointList = list;
|
||
|
||
bl = true;
|
||
|
||
SetDraw("margin");
|
||
ShowObj(Ho_Image);
|
||
//ShowObj(RM.MyROI.ho_OutlineROI, 12);
|
||
ShowObj(ho_ContCircle, 12);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
PointList = null;
|
||
}
|
||
|
||
ho_Image.Dispose();
|
||
ho_GrayImage.Dispose();
|
||
ho_Regions.Dispose();
|
||
ho_RegionOpening.Dispose();
|
||
ho_ConnectedRegions.Dispose();
|
||
ho_SelectedRegions1.Dispose();
|
||
ho_Contours.Dispose();
|
||
ho_ContCircle.Dispose();
|
||
ho_Contour.Dispose();
|
||
ho_Contours1.Dispose();
|
||
ho_Contour1.Dispose();
|
||
return bl;
|
||
}
|
||
|
||
private bool FindCircle2(HObject ho_Image, V_RectangleModel RM, out List<V_Piont> PointList)
|
||
{
|
||
bool bl = false;
|
||
|
||
HObject ho_GrayImage;
|
||
HObject ho_Regions, ho_RegionOpening, ho_ConnectedRegions, ho_RegionFillUp;
|
||
HObject ho_SelectedRegions1, ho_Contours, ho_ContCircle;
|
||
HObject ho_Contour, ho_Contours1, ho_Contour1;
|
||
|
||
// Local control variables
|
||
|
||
HTuple hv_WindowHandle = new HTuple(), hv_Row = new HTuple();
|
||
HTuple hv_Column = new HTuple(), hv_Radius = new HTuple();
|
||
HTuple hv_StartPhi = new HTuple(), hv_EndPhi = new HTuple();
|
||
HTuple hv_PointOrder = new HTuple(), hv_MetrologyHandle = new HTuple();
|
||
HTuple hv_Index = new HTuple(), hv_Row1 = new HTuple();
|
||
HTuple hv_Column1 = new HTuple();
|
||
|
||
HOperatorSet.GenEmptyObj(out ho_GrayImage);
|
||
HOperatorSet.GenEmptyObj(out ho_Regions);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionOpening);
|
||
HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
|
||
HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours);
|
||
HOperatorSet.GenEmptyObj(out ho_ContCircle);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour);
|
||
HOperatorSet.GenEmptyObj(out ho_Contours1);
|
||
HOperatorSet.GenEmptyObj(out ho_Contour1);
|
||
HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
|
||
|
||
try
|
||
{
|
||
ho_GrayImage.Dispose();
|
||
HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage);
|
||
|
||
//加深图像反差 黑的更黑 白的更白
|
||
if (RM.MyROI.ShapeA_Min > 0 || RM.MyROI.ShapeA_Max > 0)
|
||
{
|
||
HTuple hv_Mult = 255.0 / (RM.MyROI.ShapeA_Max - RM.MyROI.ShapeA_Min);
|
||
HTuple hv_Add = (-hv_Mult) * RM.MyROI.ShapeA_Min;
|
||
HOperatorSet.ScaleImage(ho_GrayImage, out ho_GrayImage, hv_Mult, hv_Add);
|
||
ShowObj(ho_GrayImage);
|
||
|
||
}
|
||
|
||
ho_Regions.Dispose();
|
||
//HOperatorSet.Threshold(ho_GrayImage, out ho_Regions, 0, 142);
|
||
HOperatorSet.Threshold(ho_GrayImage, out ho_Regions, RM.MyROI.ThresholdMin, RM.MyROI.ThresholdMax);
|
||
SetDraw("fill");
|
||
//ShowObj(ho_Regions);
|
||
//ho_RegionOpening.Dispose();
|
||
HOperatorSet.OpeningCircle(ho_Regions, out ho_RegionOpening, RM.MyROI.ShapeC_Max);
|
||
//ShowObj(ho_RegionOpening);
|
||
ho_ConnectedRegions.Dispose();
|
||
HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
|
||
//ShowObj(ho_ConnectedRegions);
|
||
ho_RegionFillUp.Dispose();
|
||
HOperatorSet.FillUp(ho_ConnectedRegions, out ho_RegionFillUp);
|
||
ho_SelectedRegions1.Dispose();
|
||
HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions1,
|
||
(new HTuple("circularity")).TupleConcat("area"), "and", (new HTuple(0.15)).TupleConcat(RM.MyROI.ShapeB_Min),
|
||
(new HTuple(1)).TupleConcat(RM.MyROI.ShapeB_Max));
|
||
ho_Contours.Dispose();
|
||
HOperatorSet.GenContourRegionXld(ho_SelectedRegions1, out ho_Contours, "border");
|
||
ShowObj(ho_ConnectedRegions);
|
||
HOperatorSet.FitCircleContourXld(ho_Contours, "algebraic", -1, 0, 0, 3, 2, out hv_Row, out hv_Column, out hv_Radius, out hv_StartPhi, out hv_EndPhi, out hv_PointOrder);
|
||
ho_ContCircle.Dispose();
|
||
//HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column, hv_Radius, 0, 6.28318, "positive", 1);
|
||
HOperatorSet.GenCircleContourXld(out ho_ContCircle, hv_Row, hv_Column, hv_Radius, 0, 6.28318, "positive", 1);
|
||
|
||
HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);
|
||
//创建找圆卡尺
|
||
//向计量模型添加一个circle或圆弧类型的计量对象,并准备矩形测量区域。模型的句柄在MetrologyHandle中传递。
|
||
//参数说明
|
||
//MetrologyHandle (输入参数)计量模型的句柄
|
||
//Row (输入参数)圆心或圆弧的行坐标(或Y)。
|
||
//Column1 (输入参数)圆心或圆弧的列(或X)坐标。
|
||
//Radius(输入参数)圆或圆弧的半径
|
||
//MeasureLength1 (70)垂直于边界的测量区域的半长(卡尺的长度)
|
||
//MeasureLength2 (1)测量区域与边界切线的半长度(卡尺的度度)
|
||
//MeasureSigma (1)用于平滑的高斯函数。建议值:0.4,0.6,0.8,1.0,1.5,2.0,3.0,4.0,5.0,7.0,10.0 典型取值范围:0.4≤measuressigma最小增量:0.01,建议增量:0.1
|
||
//MeasureThreshold (10)测量阈值,最小边缘振幅
|
||
//GenParamName 泛型参数的名称
|
||
//值列表:` distance_threshold `, ` end_phi `, ` instances_outside_measure_regions `, ` max_num_iterations `, ` measure_distance `, ` measure_interpolation `, ` measure_select `, ` measure_transition `, ` min_score `, ` num_instances `, ` num_measures `, ` point_order `, ` rand_seed `, ` start_phi `
|
||
//GenParamValu 泛型参数的值
|
||
//Index(输出参数)创建的计量对象的索引
|
||
// HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, RM.MyROI.hv_Row, RM.MyROI.hv_Column, RM.MyROI.hv_Radius, 300, 5, 1, 30, new HTuple(), new HTuple(), out hv_Index);
|
||
|
||
|
||
HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, hv_Row, hv_Column, hv_Radius, 145, 5, 1, 30, new HTuple(), new HTuple(), out hv_Index);
|
||
// HOperatorSet.AddMetrologyObjectCircleMeasure(hv_MetrologyHandle, hv_Row, hv_Column, hv_Radius, 45, 1, 1, 5, new HTuple(), new HTuple(), out hv_Index);
|
||
|
||
ho_Contour.Dispose();
|
||
HOperatorSet.GetMetrologyObjectModelContour(out ho_Contour, hv_MetrologyHandle, "all", 1.5);
|
||
|
||
HOperatorSet.GetMetrologyObjectMeasures(out ho_Contours1, hv_MetrologyHandle, "all", "all", out hv_Row1, out hv_Column1);
|
||
HOperatorSet.ApplyMetrologyModel(Ho_Image, hv_MetrologyHandle);
|
||
HTuple hv_Parameter = new HTuple();
|
||
HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type", "all_param", out hv_Parameter);
|
||
ho_Contour1.Dispose();
|
||
HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour1, hv_MetrologyHandle, "all", "all", 1.5);
|
||
HOperatorSet.ClearMetrologyModel(hv_MetrologyHandle);
|
||
|
||
|
||
int a = 0;
|
||
V_Piont p = new V_Piont();
|
||
List<V_Piont> list = new List<V_Piont>();
|
||
foreach (var item in hv_Parameter.ToDArr())
|
||
{
|
||
if (a == 0)
|
||
{
|
||
p = new V_Piont() { hv_RefRow = item };
|
||
a++;
|
||
}
|
||
else if (a == 1)
|
||
{
|
||
p.hv_RefColumn = item;
|
||
a++;
|
||
}
|
||
else if (a == 2)
|
||
{
|
||
a = 0;
|
||
list.Add(p);
|
||
}
|
||
|
||
}
|
||
PointList = list;
|
||
|
||
|
||
|
||
|
||
bl = true;
|
||
|
||
|
||
ShowObj(ho_Contours1, 12);
|
||
ShowObj(ho_Contour1, 12);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
PointList = null;
|
||
}
|
||
|
||
ho_Image.Dispose();
|
||
ho_GrayImage.Dispose();
|
||
ho_Regions.Dispose();
|
||
ho_RegionOpening.Dispose();
|
||
ho_ConnectedRegions.Dispose();
|
||
ho_SelectedRegions1.Dispose();
|
||
ho_Contours.Dispose();
|
||
ho_ContCircle.Dispose();
|
||
ho_Contour.Dispose();
|
||
ho_Contours1.Dispose();
|
||
ho_Contour1.Dispose();
|
||
return bl;
|
||
}
|
||
}
|
||
}
|