279 lines
7.9 KiB
C#
279 lines
7.9 KiB
C#
using Community;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using HalconDotNet;
|
||
using System.Collections.ObjectModel;
|
||
using System.IO;
|
||
|
||
namespace Model.Vision
|
||
{
|
||
/// <summary>
|
||
/// 矩形区域模型
|
||
/// </summary>
|
||
public class V_RectangleModel : NotificationObject
|
||
{
|
||
public int ID { get; set; }
|
||
|
||
#region 区域轮廓参数
|
||
/// <summary>
|
||
/// 项目ID
|
||
/// </summary>
|
||
public int VeiID { get; set; }
|
||
|
||
/// <summary>
|
||
/// 区域类型,1:自由区域 2:图像校正区域
|
||
/// </summary>
|
||
public int AreaType { get; set; }
|
||
|
||
/// <summary>
|
||
/// 起点纵向坐标
|
||
/// </summary>
|
||
public double Point_Row1 { get; set; }
|
||
/// <summary>
|
||
/// 起点横向坐标
|
||
/// </summary>
|
||
public double Point_Column1 { get; set; }
|
||
/// <summary>
|
||
/// 终点纵向坐标
|
||
/// </summary>
|
||
public double Point_Row2 { get; set; }
|
||
/// <summary>
|
||
/// 终点横向坐标
|
||
/// </summary>
|
||
public double Point_Column2 { get; set; }
|
||
|
||
/// <summary>
|
||
/// 矩形区域轮廓
|
||
/// </summary>
|
||
public HObject ho_RectangleModel;
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 支持文件名称
|
||
/// </summary>
|
||
public string HelpFileName { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否读取标定文件
|
||
/// </summary>
|
||
public bool WhetherReadFile { get; set; }
|
||
|
||
/// <summary>
|
||
/// 九点标定参数
|
||
/// </summary>
|
||
public HTuple hv_JiuDianCalibrationPar = null;
|
||
|
||
|
||
|
||
#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 我的ROI
|
||
|
||
private V_ROI myROI;
|
||
/// <summary>
|
||
/// 我的ROI
|
||
/// </summary>
|
||
public V_ROI MyROI
|
||
{
|
||
get { return myROI; }
|
||
set
|
||
{
|
||
myROI = value==null?new V_ROI():value;
|
||
this.RaisePropertyChanged("MyROI");
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 我的ROI集合
|
||
private ObservableCollection<V_ROI> myRoiList;
|
||
/// <summary>
|
||
/// 我的ROI集合
|
||
/// </summary>
|
||
public ObservableCollection<V_ROI> MyRoiList
|
||
{
|
||
get { return myRoiList; }
|
||
set
|
||
{
|
||
myRoiList = value==null?new ObservableCollection<V_ROI>():value;
|
||
this.RaisePropertyChanged("MyRoiList");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 模板图片
|
||
/// </summary>
|
||
public HObject ModelImage;
|
||
|
||
|
||
public V_RectangleModel()
|
||
{
|
||
WhetherReadFile = true;
|
||
MyROI = new V_ROI() { ROIType = 1 };
|
||
MyRoiList = new ObservableCollection<V_ROI>();
|
||
}
|
||
|
||
|
||
|
||
#region 实例化矩形轮廓
|
||
/// <summary>
|
||
/// 实例化矩形轮廓
|
||
/// </summary>
|
||
public void Instantiation()
|
||
{
|
||
WhetherReadFile = true;
|
||
HOperatorSet.GenEmptyObj(out ho_RectangleModel);
|
||
//获取产品模型
|
||
ho_RectangleModel.Dispose();
|
||
HOperatorSet.GenRectangle1(out ho_RectangleModel, Point_Row1, Point_Column1, Point_Row2, Point_Column2);
|
||
}
|
||
#endregion
|
||
|
||
#region 标定文件的存取
|
||
/// <summary>
|
||
/// 保存标定文件
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool SaveCalibrationFile(HTuple hv_CalibrationPar)
|
||
{
|
||
this.HelpFileName = VeiID + "_" + this.ID;
|
||
//先确保标定参数文件已存在
|
||
string filePath = @"Calibration/" + HelpFileName + ".tup"; //相机标定参数保存路径
|
||
|
||
if (!Directory.Exists(@"Calibration/"))
|
||
{
|
||
Directory.CreateDirectory(@"Calibration/");
|
||
}
|
||
try
|
||
{
|
||
HOperatorSet.WriteTuple(hv_CalibrationPar, filePath);
|
||
this.hv_JiuDianCalibrationPar = hv_CalibrationPar;
|
||
return true;
|
||
}
|
||
catch (Exception)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
#region 第二种保存文件的方法
|
||
//先确保标定参数文件已存在
|
||
// string filePath = @"Calibration/" + HelpFileName + ".dat"; //相机标定参数保存路径
|
||
|
||
//if (!Directory.Exists(@"Calibration/"))
|
||
//{
|
||
// Directory.CreateDirectory(@"Calibration/");
|
||
//}
|
||
|
||
|
||
//if (!File.Exists(filePath))
|
||
//{
|
||
// File.Create(filePath).Dispose();
|
||
//}
|
||
|
||
|
||
//if (File.Exists(filePath))
|
||
//{
|
||
// HTuple hv_SerializedItemHandle, hv_FileHandle;
|
||
// //保存标定参数
|
||
// HOperatorSet.SerializeHomMat2d(hv_CalibrationPar, out hv_SerializedItemHandle);
|
||
// HOperatorSet.OpenFile(filePath, "output_binary", out hv_FileHandle);
|
||
// HOperatorSet.FwriteSerializedItem(hv_FileHandle, hv_SerializedItemHandle);
|
||
// HOperatorSet.CloseFile(hv_FileHandle);
|
||
// this.hv_JiuDianCalibrationPar = hv_CalibrationPar;
|
||
// this.WhetherReadFile = true;
|
||
// return true;
|
||
//}
|
||
//else
|
||
//{
|
||
// return false;
|
||
//}
|
||
#endregion
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 读取标定参数
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool ReadCalibrationPar()
|
||
{
|
||
if (!WhetherReadFile && hv_JiuDianCalibrationPar != null)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
this.HelpFileName = VeiID + "_" + this.ID;
|
||
string filePath = @"Calibration/" + HelpFileName + ".tup"; //相机标定参数保存路径
|
||
bool bl = false;
|
||
try
|
||
{
|
||
if (File.Exists(filePath))
|
||
{
|
||
HOperatorSet.ReadTuple(filePath, out hv_JiuDianCalibrationPar);
|
||
bl = true;
|
||
}
|
||
}
|
||
catch (Exception)
|
||
{
|
||
bl= false;
|
||
}
|
||
WhetherReadFile = !bl;
|
||
return bl;
|
||
|
||
#region 第二种读取文件的方法
|
||
//string filePath = @"Calibration/" + HelpFileName + ".dat"; //相机标定参数保存路径
|
||
|
||
//if (!File.Exists(filePath))
|
||
//{
|
||
// this.hv_JiuDianCalibrationPar = null;
|
||
// return false;
|
||
//}
|
||
|
||
//try
|
||
//{
|
||
// HTuple hv_FileHandle1 = null, hv_SerializedItemHandle1 = null;
|
||
// HTuple hv_HomMat2D1 = null;
|
||
// //读取
|
||
// HOperatorSet.OpenFile(filePath, "input_binary", out hv_FileHandle1);
|
||
// HOperatorSet.FreadSerializedItem(hv_FileHandle1, out hv_SerializedItemHandle1);
|
||
// HOperatorSet.DeserializeHomMat2d(hv_SerializedItemHandle1, out hv_HomMat2D1);
|
||
// HOperatorSet.CloseFile(hv_FileHandle1);
|
||
// this.WhetherReadFile = false;
|
||
// this.hv_JiuDianCalibrationPar = hv_HomMat2D1;
|
||
// return true;
|
||
//}
|
||
//catch (Exception)
|
||
//{
|
||
// return false;
|
||
//}
|
||
#endregion
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|